windows.open、 window.location.href

windows.open("URL","窗口名称","窗口外观设定");打开新窗口,window对象的方法 

不一定打开新窗口,只要有窗口的名称和window.open中第二个参数中的一样就会将这个窗口替换,可以iframe、frame中代替location.href 

<iframe name="a"></iframe>   
<input type=button onclick="window.open('1.htm','aa','')"> 
效果同
<input type=button onclick="self.frames['a'].location.href='1.htm'"> 

示例:

同时弹出两个窗口 ,对源代码稍微改动一下: 

function openwin() { 
  window.open ("page.html", "newwindow", "height=100, width=100, top=0, left=0,toolbar=no, menubar=no,
     scrollbars=no, resizable=no, location=n o, status=no")   window.open ("page2.html", "newwindow2", "height=100, width=100, top=1 00, left=100,toolbar=no, menubar=no,
          scrollbars=no, resizable=no, loca tion=no, status=no")   window.open("http://jxjymember.cdeledu.com/cdel_jxjy_member/groupInfo/view.do?op=goSearchFullName&fullName=" + fullName); }

为避免弹出的2个窗口覆盖,用top和left控制一下弹出的位置不要相互覆盖即可

注意:2个窗口的name(newwindows和newwindow2)不要相同,或者干脆全部为空。 

 

window.location.href 只能在当前页面打开,window对象的属性

常用形式:

self.location.href;//当前页面打开URL页面

[window.]location.href;//当前页面打开URL页面

this.location.href;//当前页面打开URL页面

location.href;// 当前页面打开URL页面

parent.location.href;//在父页面打开新页面

top.location.href;//在顶层页面打开新页面           

注意:

1、如果页面中自定义了frame,那么可将parent、self、top换为自定义frame的名称,效果是在frame窗口打开url地址。

2、window.location.href=window.location.href; 刷新当前页面

window.location.Reload();刷新当前页面,有数据要提交时会提示是否window.location.href=window.location.href;向指定的url提交数据.

3、有时浏览器会屏蔽window.open,避免弹出广告窗口等

4、window.open()是可以在一个网站上打开另外的一个网站的地址 
window.location()是只能在一个网站中打开本网站的网页 

 

href=”#”href=”javascript(0)”

<a href="#"> 点击链接后,页面会向上滚到页首,# 默认锚点为 #TOP,即刷新页面

<a href="javascript:void(0)" onClick="window.open()"> 点击链接后,页面不动,只打开链接,需要刷新页面时谨慎使用

<a href="#" onclick="javascript:return false;"> 作用同上,不同浏览器会有差异。

<a href="####"></a>
<a href="javascript:void(0)"></a>
<a href="javascript:void(null)"></a>
<a href="#" onclick="return false"></a>

原文地址:https://www.cnblogs.com/whatarewords/p/10717933.html