天天看點

window.open被IE攔截的解決辦法

由于在使用window.open時,在很多情況下,彈出的視窗會被浏覽器阻止,但若是使用a連結target='_blank',則不會,基于這一特點,自己封裝了一個open方法:

function openwin(url) {

    var a = document.createElement("a");

    a.setAttribute("href", url);

    a.setAttribute("target", "_blank");

    a.setAttribute("id", "openwin");

    document.body.appendChild(a);

    a.click();

}

使用方法:

在html頁面裡面添加<body></body>标簽,如果已有,則不加。

在js塊中,直接調用上面的openwin('url')即可。

轉自:http://blog.csdn.net/fanfanjin/article/details/6858168

繼續閱讀