Mobile Safari-Javascript打开选项卡,不会失去对当前页面的关注

Mobile Safari - Javascript open tab without losing focus on current page

本文关键字:当前页 失去 Safari-Javascript 选项 Mobile      更新时间:2023-09-26

我目前正在开发一个网页,当访问该网页时,它会在移动safari中打开另外两个网页。

唯一的问题是,当加载新选项卡时,浏览器会将注意力集中在要加载的最后一个选项卡上。

我曾尝试设置Safari设置"打开链接->在后台",但这似乎只会让你选择按住链接,然后手动选择在后台打开链接(从而保持专注于当前页面)。

有没有办法在Mobile Safari中使用javascript自动打开网络链接,而不会失去对当前网页的关注?

下面是我当前使用的代码示例。

<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<html>
<head>
</head>
<body>
<a class="site" href="bbcNews/www.bbc.co.uk/news/index.html" target="_blank">Open Tabs</a>
    <script>
        $('a').each(function () {
            var clk = document.createEvent("MouseEvents");
            clk.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, true, 0, null);
            this.dispatchEvent(clk);
        });
    </script>
</body>
</html>    

我很长一段时间都在使用这种逻辑来处理"pop-unders"。希望这对您有用:-基本思想是在新的选项卡中打开页面本身,同时将"旧"选项卡/页面重定向到的其他位置

  function popunder_redirect(){
      window.open("#tab");
      window.location="http://redirecturl.com";
    }

现在,正如你所看到的,你的原始页面链接旁边有一个哈希链接(#tab),你可以将其用作某种虚假历史记录,通过检查页面加载来调整你的javascript或其他页面进度:

jQuery(document).ready(function(){

var hashValue = window.location.hash;     //get hash value
//check for hash value
if (hashValue!=undefined && hashValue=="#tab")
{
      //display progressed page}
else{
     //display start page
}
});