请问top.location.href的值可能为undefined吗?在什么情况下获得

解决方案 »

  1.   

    你的代碼在文檔中, location.href就是文檔的地址及參數, 你說能不能為undefined
      

  2.   

    按楼上的意思,应该是不可能为undefined吧,是这样吧,那为什么有
    <script language="JavaScript" type="text/javascript">
    //防止引用
    if (top.location.href == undefined) {location.href='http://77ya.com/index.html'};
    if (self.location.href != top.location.href) {top.location.href=self.location.href;};
    </script>这种代码呢,据介绍这种代码的作用是用来防止别人通过iframe恶意调用页面
    请问下这里的top.location.href == undefined应该怎么理解?谢谢
      

  3.   

    location.href返回的是对象,肯定可以为undefined的,为undefined就是说明他的top这个对象是undefined,这样也就肯定只有返回一个undefined
      

  4.   


    href是location的默认属性, 类型是字符串.location对象包含关于当前 URL 的信息。
    这表明, 如果文档没有打开, 就不存在他的地址对象.
    如果有location, 就一定有他的href