美文网首页
location.href window.open跳转问题

location.href window.open跳转问题

作者: lovelydong | 来源:发表于2018-07-23 15:24 被阅读0次

window.open方法容易被各大浏览器拦截

window.location.href = linkUrl 或者window.location.replace()来替代当前的url

(注)window.location.href 不兼容华为自带浏览器 window.location.replace() 没影响

另一个解决方案

<!DOCTYPE HTML>
<html lang="en-US">
<head>
   <meta charset="UTF-8">
   <title></title>
</head>
<body>
   <a id='links' href="#" style='display:none;'></a>
   <script type="text/javascript">
      var obj = document.getElementById('links');
      obj.href = "http://www.baidu.com";
      obj.click();
   </script>
</body>
</html>

相关文章

网友评论

      本文标题:location.href window.open跳转问题

      本文链接:https://www.haomeiwen.com/subject/perjmftx.html