location.href window.open跳转问题

2018-07-23  本文已影响0人  lovelydong

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>
上一篇 下一篇

猜你喜欢

热点阅读