1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>JavaScript-打開新窗口(window.open)</title> 6 <script type="text/javascript"> 7 window.open('https://www.cnblogs.com/dhnblog/','_blank','width=300,height=300,menubar=no,toobar=no,status=no,scrollbars=yes'); 8 // window.open('https://www.cnblogs.com/dhnblog/','_self','width=300,height=100,menubar=no,toobar=no,status=no,scrollbars=yes'); 9 //window.open('https://www.cnblogs.com/dhnblog/','_top','width=300,height=300,menubar=no,toobar=no,status=no,scrollbars=yes'); 10 </script> 11 </head> 12 <body> 13 </body> 14 </html> 代碼含義:打開https://www.cnblogs.com/dhnblog/博客,大小為300px*200px,無菜單,無工具欄,無狀態(tài)欄,有滾動條窗口;其中open() 方法可以查找一個已經(jīng)存在或者新建的瀏覽器窗口。 語法結(jié)構(gòu): window.open([URL], [窗口名稱], [參數(shù)字符串]) 參數(shù)說明: URL:可選參數(shù),在窗口中要顯示網(wǎng)頁的網(wǎng)址或路徑。如果省略這個參數(shù),或者它的值是空字符串,那么窗口就不顯示任何文檔。 窗口名稱:可選參數(shù),被打開窗口的名稱。
e.g:打開https://www.cnblogs.com/dhnblog/網(wǎng)頁,將在新窗體中打開,寬為600,高為400,距屏頂100像素,屏左0像素;當點擊按鈕時,打開新窗口。 1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>window.open</title> 6 <script type="text/javascript"> 7 function Wopen(){ 8 window.open('https://www.cnblogs.com/dhnblog/','dhn','width=600,height=400,top=100px,left=0,menubar=no,toobar=no,status=no,scrollbars=yes'); 9 } 10 </script> 11 </head> 12 <body> 13 <input name="button" type="button" onClick="Wopen()" value="點擊我,打開新窗口!" / > 14 </body> 15 </html> 總結(jié):注意window.open('https://www.cnblogs.com/dhnblog/','dhn','width=600,height=400,top=100px,left=0,menubar=no,toobar=no,status=no,scrollbars=yes');里面的這個number值是要用等號的,如果你用的是這個分號,像這樣的話window.open('https://www.cnblogs.com/dhnblog/','dhn','width:600,height:400,top:100px,left:0,menubar=no,toobar=no,status=no,scrollbars=yes');不管你怎么修改number,你發(fā)現(xiàn)這個在新窗口顯示目標網(wǎng)頁和這個目標網(wǎng)頁真沒啥區(qū)別,這時你心里是不是有些懷疑人生了... |
|