0

I know that there are lots of duplicate questions like mine but I couldn't find any solution. I'm having trouble with opening a new tab in my code. I want to open a new tab - not a window - without any click on any button, and I need it to run automatically.

This is my code but it open's a new window instead of a new tap.

code:

if (isset($_POST['check'])){
  ?><script>window.open('reports/education_efficacy.php','_blank');</script><?php
}

meta refresh version: (it redirects to the target page in the same page, and I wonder is there any way to redirect to a new tab?)

if (isset($_POST['check'])){
  echo "<meta http-equiv=\"refresh\" content=\"0; URL=javascript:window.open('reports/relation_with_health.php\','_new');\">";
}
faintsignal
  • 1,828
  • 3
  • 22
  • 30
anonymox
  • 419
  • 1
  • 9
  • 32
  • possible duplicate of [Open a URL in a new tab using JavaScript](http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-using-javascript) – Mark Baker Apr 18 '14 at 15:27
  • As i said there are duplicate questions like mine but there is no solution for my problem , so please do not close my post. – anonymox Apr 18 '14 at 15:33
  • There is no solution that will work in all cases, and attempting to restrict how a user uses there browser isn't a good idea – Mark Baker Apr 18 '14 at 15:34
  • @MarkBaker I just need one solution for this matter , I need to open a new tab without any button clicking or etc just if the condition is true open a new tab . – anonymox Apr 18 '14 at 15:38
  • is there any way to auto submit a form via jquery or javascript and open a windows in new tab ? – anonymox Apr 18 '14 at 15:51

2 Answers2

0

try this:

window.open('reports/relation_with_health.php\','_blank')
Amit Kumar
  • 3,384
  • 6
  • 25
  • 42
  • is there any way to auto submit a form via jquery or javascript and open a windows in new tab ? – anonymox Apr 18 '14 at 16:00
  • There is a way to auto submit form using jquery. you can use $('#yourformId').submit(); to submit a form using jquery. – Amit Kumar Apr 18 '14 at 16:06
0

With the bel open a new tap and stay in current tap (crtl+click) function like.

java code :

<script>
        document.getElementById("test").addEventListener("click", openNewBackgroundTab, false);

        function openNewBackgroundTab(url){
            var a = document.createElement("a");
             a.href = url;
            var evt = document.createEvent("MouseEvents");    
            evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null);
            a.dispatchEvent(evt);
        }
    </script>

html code :

<a href="#" id="test" onclick="openNewBackgroundTab('reports/education_efficacy.php')" >education efficacy</a>
Mohammad_Hosseini
  • 2,481
  • 3
  • 30
  • 53