转 top.location.href和localtion.href有什么不同

来源:互联网 发布:思迅软件u盘 编辑:程序博客网 时间:2024/04/29 18:40
<div class="postTitle" style="font-size: 14.7px; font-weight: bold; margin-bottom: 10px; font-family: verdana, Arial, helvetica, sans-seriff;"><span style="color: rgb(75, 75, 75); line-height: 19.200000762939453px; font-size: 14px;">top.location.href=”url”          <span style="white-space: pre;"></span>在顶层页面打开url(跳出框架)   </span><a target=_blank target="_blank" name="baidusnap0" class="  " style="color: rgb(75, 75, 75); line-height: 19.200000762939453px; background-color: rgb(240, 240, 240); font-size: 14px;"></a></div><div class="postTitle" style="font-size: 14.7px; font-weight: bold; margin-bottom: 10px; font-family: verdana, Arial, helvetica, sans-seriff;"><span style="color: black; line-height: 19.200000762939453px; font-size: 14px; background-color: rgb(255, 255, 102);">self.location.href</span><span style="color: rgb(75, 75, 75); line-height: 19.200000762939453px; font-size: 14px;">=”url”         <span style="white-space: pre;"></span>仅在本页面打开url地址   </span></div><div class="postTitle" style="color: rgb(75, 75, 75); font-size: 14.7px; font-weight: bold; margin-bottom: 10px; font-family: verdana, Arial, helvetica, sans-seriff;"><span style="line-height: 19.200000762939453px; font-size: 14px;">parent.location.href=”url”     在父窗口打开Url地址   </span></div><div class="postTitle" style="color: rgb(75, 75, 75); font-size: 14.7px; font-weight: bold; margin-bottom: 10px; font-family: verdana, Arial, helvetica, sans-seriff;"><span style="line-height: 19.200000762939453px; font-size: 14px;">this.location.href=”url”       <span style="white-space: pre;"></span>用法和self的用法一致      </span></div><div class="postTitle" style="color: rgb(75, 75, 75); font-size: 14.7px; font-weight: bold; margin-bottom: 10px; font-family: verdana, Arial, helvetica, sans-seriff;"><span style="line-height: 19.200000762939453px; font-size: 14px;"></span></div><div class="postTitle" style="color: rgb(75, 75, 75); font-size: 14.7px; font-weight: bold; margin-bottom: 10px; font-family: verdana, Arial, helvetica, sans-seriff;"><span style="line-height: 19.200000762939453px; font-size: 14px;">if (top.location == self.location) 判断当前location 是否为顶层来 </span><span style="font-size: 14px; line-height: 1.5; color: rgb(250, 128, 114);">禁止frame引用</span><span style="line-height: 19.200000762939453px; font-size: 14px;">   </span></div><div class="postTitle" style="color: rgb(75, 75, 75); font-size: 14.7px; font-weight: bold; margin-bottom: 10px; font-family: verdana, Arial, helvetica, sans-seriff;"><span style="line-height: 19.200000762939453px; font-size: 14px;">如果页面当中有自定义的frame的话,也可以将parent  self   top换为自定义frame的名称      效果就是在自定义frame窗口打开url地址</span><p style="margin: 10px auto; line-height: 19.200000762939453px;"></p><p style="margin: 10px auto; line-height: 19.200000762939453px;">实际中可能这样使用</p><p style="margin: 10px auto; line-height: 19.200000762939453px;">        if(top !== self){        top.location.href = location.href;         }   <span style="line-height: 1.5; color: rgb(250, 128, 114);">禁止frame引用</span></p><p style="margin: 10px auto; line-height: 19.200000762939453px;"><span style="line-height: 1.5; color: rgb(250, 128, 114);">http://blog.csdn.net/lisheng19870305/article/details/41074893</span></p></div>
0 0