Jquery查看iframe位置是否已更改

时间:2013-09-28 22:24:18

标签: javascript html

所以我想检查一下我的框架位置是否已经改变

function myFunction()
{
  setInterval(function(){alert("Hello")},3000);

  if (document.getElementById("myiframe").src = 'http://www.constant-creative.com/login';)
  {
  } 
  else 
  {
    $( "#loginframe" ).hide();
  }
}

这就是我目前所拥有的

1 个答案:

答案 0 :(得分:1)

在javascript中,=assignment operator。例如

// foo can be whatever
foo = 'bar'
// now foo is 'bar' 

但是如果你想比较一下,可以使用comparison operators ==(相等运算符)或===(严格相等运算符)。区别在于==仅比较值,===比较值和类型。例如

var a = 1;
a ==  1;     // yes
a === 1;     // yes
a ==  true;  // yes
a === true;  // NO!
// a is still 1

如果您想否定比较运算符(即,知道两件事情是否不同),您可以使用!=!==。例如,

1 !=  1;     // no
1 !== 1;     // no
1 !=  true;  // no
1 !== true;  // YES!

如果您知道要比较的内容的类型相同,那么=====将具有相同的行为,但===会更快。


在您的情况下,您可以使用类似

的内容
function myFunction()
{
  if (document.getElementById("myiframe").src
      !==
      'http://www.constant-creative.com/login';
  ) {
    $( "#loginframe" ).hide();
  }

  setTimeout(myFunction,3000);
}
myFunction();