0

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.

maciekm
  • 257
  • 1
  • 5
  • 28
  • 4
    trying to dictate to a user how they use there browser is a BAD idea –  Mar 24 '14 at 19:24
  • 1
    possible duplicate of [Check if window is already open window.open](http://stackoverflow.com/questions/12138236/check-if-window-is-already-open-window-open) – Patrick Q Mar 24 '14 at 19:30

2 Answers2

1

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.

Luke Joshua Park
  • 9,527
  • 5
  • 27
  • 44
0

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!

Tzar
  • 1,761
  • 2
  • 14
  • 21