當前位置:生活全書館 >

IT科技

> open不打開新窗口 window

open不打開新窗口 window

1、window.open不打開新窗口的原因:

某些瀏覽器為了安全起見,可能會阻止window.open打開的鏈接url。

2、解決方法:

需要用户進行瀏覽器設置允許彈新頁,讓用户設置瀏覽器是極不可取的做法,可以利用超鏈接打開的url,利用超鏈接打開的url是不會被攔截的。

window.open不打開新窗口

3、window.open的用法容易忽視的細節:

window.open方法有三個參數:  

window.open(url, [name], [configuration])

其中:

url, 為要新打開頁面的url

name,為新打開窗口的名字,可以通過此名字獲取該窗口對象

configuration,為新打開窗口的一些配置項,比如是否有菜單欄、滾動條、長高等等信息

例如,新打開一個沒有菜單欄、標題欄、工具欄,但是有滾動條、狀態欄、地址欄且可伸縮窗口的方法調用如下:

window.open("index.html","newWindow","menubar=0,scrollbars=1, resizable=1,status=1,titlebar=0,toolbar=0,location=1");

容易忽略的地方就是:

新打開窗口名字可以是自定義的值,此外還可以是以下幾個值,與超鏈接a的target屬性值相同

window.open不打開新窗口 第2張

窗口name值描述
_blank默認的,在新窗口打開鏈接的url
_self在當前窗口打開鏈接url
_parent在父窗口打開鏈接url
_top在頂級窗口打開url
framename

在指定的框架中打開鏈接url


4、window.open打開新窗口還是打開新標籤頁:

調用window.open是打開新窗口,還是打開新標籤頁,其實沒有什麼要緊關係,但是有些需求在這方面有很強的意願時,就得區分一下,具體的打開什麼要根據具體情況來定。

window.open(url)或者window.open(url, name),其中name為_blank

標準瀏覽器、IE9+是新標籤打開鏈接url

ie6-8是新窗口打開鏈接url

window.open(url, name),其中name為非_blank的其他4個值

此時會會在指定窗口或者frame打開鏈接url

window.open(url, name, configration)

只要配置了configration,所有瀏覽器都是新窗口打開鏈接url

標籤: 新窗口 windowopen
  • 文章版權屬於文章作者所有,轉載請註明 https://shqsg.com/zh-hk/dianzi/eq3m92.html