曲奇饼 发表于 2019-11-14 21:35:31

JS打开新窗口的2种方式

本帖最后由 曲奇饼 于 2019-11-14 22:35 编辑

1.超链接<a href="//www.zgxsh.net" title="脚本之家">Welcome</a>
等效于js代码
window.location.href="//www.zgxsh.net";   //在同当前窗口中打开窗口

2.超链接<a href="//www.zgxsh.net" title="脚本之家" target="_blank">Welcome</a>
等效于js代码
window.open("//www.zgxsh.net");               //在另外新建窗口中打开窗口


--------

*.location.href 用法:
  top.location.href=”url”          在顶层页面打开url(跳出框架)
  self.location.href=”url”         仅在本页面打开url地址
  parent.location.href=”url”      在父窗口打开Url地址
  this.location.href=”url”       用法和self的用法一致
   if (top.location == self.location) 判断当前location 是否为顶层来 禁止frame引用
 如果页面当中有自定义的frame的话,也可以将parentself   top换为自定义frame的名称
   效果就是在自定义frame窗口打开url地址


top.location是在顶层frame中打开新页
window.location是在当前frame中打开新页
parent.location 在当前窗口的父窗口打开Url地址
页: [1]
查看完整版本: JS打开新窗口的2种方式