jiangtuzi

由于在使用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();
}

调用方式如下:

<input type="button" id="btn" value="百度" onclick="openwin(\'http://www.baidu.com\');" />

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-06-17
  • 2022-12-23
  • 2021-07-24
  • 2021-11-12
猜你喜欢
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2022-01-07
相关资源
相似解决方案