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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM