19

I have a form with action e.g. register.php

I also have a Google group API link -

https://groups.google.com/group/GROUPNAME/boxsubscribe?p=ConfirmExplanation&email=EMAIL_ID&_referer&hl=en

in short... Is there any PHP function for open page in new tab; on page load...

j0k
  • 22,600
  • 28
  • 79
  • 90
suiz
  • 377
  • 1
  • 2
  • 13

5 Answers5

13

Use the target attribute on your anchor tag with the _blank value.

Example:

<a href="http://google.com" target="_blank">Click Me!</a>
Terry Harvey
  • 9,286
  • 1
  • 17
  • 22
  • 3
    Thanx for reply... this is html anchor hyper reference But I want rto open in new tab on page load, not on click... – suiz Oct 09 '12 at 09:12
  • 4
    He is expecting through PHP. – AsgarAli Jan 09 '16 at 09:49
  • @Ali Impossible. PHP is a server side language. – Terry Harvey Jan 09 '16 at 15:32
  • Yes it's not possible but you should mention that it's not possible through PHP – AsgarAli Jan 09 '16 at 15:47
  • Please don't use `_blank`. Read more about it here: https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Do_not_use_target_blank or https://stackoverflow.com/questions/4964130/target-blank-vs-target-new/8867079#8867079. You could use: `_newtab`. – Julian Jun 14 '18 at 09:54
  • And how do you change this script to open in same/current tab? –  Jun 28 '20 at 18:33
11

You can write JavaScript code in your file .

Put following code in your client side file:

<script>

    window.onload = function(){
         window.open(url, "_blank"); // will open new tab on window.onload
    }
</script>

using jQuery.ready

<script>
  $(document).ready(function(){
      window.open(url, "_blank"); // will open new tab on document ready
  });
</script>
Anoop
  • 23,044
  • 10
  • 62
  • 76
  • window.open(url, "_blank"); this code is open page as a pop-up. But I want to open in new tab insted of new window... – suiz Oct 09 '12 at 09:10
  • @user1573254 opening new tab is default behavior. I am using it in my application and it always open an new tab. to Open in new window I have to provide height and width as 3rd param. – Anoop Oct 09 '12 at 09:18
  • 2
    He is expecting through PHP. – AsgarAli Jan 09 '16 at 09:49
  • @Ali You can write JavaScript inside PHP generated page – Anoop Jan 13 '16 at 13:48
2

You can use both PHP and javascript. Perform your php codes in the backend and redirect to a php page. On the php page you redirected to add the code below:

<?php if(condition_to_check_for){ ?>

    <script type="text/javascript">
       window.open('url_goes_here', '_blank');
    </script>

<?  } ?>
andydoe
  • 214
  • 2
  • 6
1

You can simply use target="_blank" to open a page in a new tab

<a href="whatever.php" target="_blank">Opens On Another Tab</a>

Or you can simply use a javascript for onload

<body onload="window.open(url, '_blank');">
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
0

This is a trick,

function OpenInNewTab(url) {

  var win = window.open(url, '_blank');
  win.focus();
}

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="OpenInNewTab();">Something To Click On</div>
Rohan Khude
  • 4,455
  • 5
  • 49
  • 47