duanpacan2583
2014-03-24 19:21
浏览 76

防止在浏览器中打开另一个相同的选项卡

Let's say I have main.php and page1.html on my www apache server. Part of main.php:

 ...
 <script> 
   function openNewTab(){
   var win=window.open('page1.html', '_blank');
       win.focus();
   };
 </script>
 ... 
 <?php
  echo  "<p><a href='' onclick='openNewTab(); return false;'>start</a></p>";
 ?>

When I click link above, I have opened two tabs: main.php and page1.html. And my aim is to prevent user opening another tab with page1.html, when he press link on main.php. Or , when user click link on main.php, tab with page1.html should be refreshed, but new tab shouldn't be opened.

thanks in advance.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doutuo2829 2014-03-24 19:31
    已采纳

    You can try it like this:

     <script> 
       function openNewTab(){
       var win=window.open('page1.html', 'mypage1');
           win.location.reload();
           win.focus();
       };
     </script>
    

    But now, this doesn't guarantee that it'll open in a new tab only. This will depend on the user's browser settings. By default it opens in a new tab, so it might work out for you!

    Check and see if it helps!

    点赞 打赏 评论
  • duanjiong5023 2014-03-24 19:28

    You can't control a browsers behaviour, and if you could, it would be highly frowned upon. The user should always have full control over what tabs open where. You could actually achieve this using AJAX and Cookies but mobile compatability would be a big headache.

    I would recommend finding a way to solve your problem that keeps the user in control of their browser.

    点赞 打赏 评论

相关推荐 更多相似问题