Open a page before loading the header

Asked

Viewed 80 times

-1

The point is, I’m trying to open up a page before the header from the main page is executed;

<?php
   
echo("<script language=\"javascript\">");
echo("window.open('teste.php', '_blank');");
echo("</script>");
header("Location: http://www.google.com");

?>

I’ve tried it this way, but when the page opens it goes straight to header(redirecting to the google page and ignoring the opening of "test.php").

I’ve tried for a sleep before the header, but apparently also doesn’t make much sense in the execution. Why he just keeps ignoring and going straight to header.

Some alternative?

Note: The "test.php" page has to necessarily open in a new tab, without being a popup or something similar, with the target = _blank as in the little code I left behind

  • Strange that, should open test.php in new tab and generate an error Cannot Modify header information - headers already sent by

2 answers

0

Strange that vai direto no header , should open test.php in new tab and generate an error Cannot Modify header information - headers already sent by .....

You can open both pages in the same script, a _blank and another _self

echo("<script language=\"javascript\">");
echo("window.open('teste.php', '_blank');");
echo("window.open('http://www.google.com', '_self');");
echo("</script>");

Another way is to use meta refresh

<?php

echo("<script language=\"javascript\">");
echo("window.open('teste.php', '_blank');");
echo("</script>");

echo "<meta http-equiv=\"refresh\" content=\"0;URL='http://www.google.com'\" />";

?>

0

I couldn’t do it for PHP. But an alternative would be to use Javascript both to open the pop-up and to redirect:

<?php
echo "<script type='text/javascript'>window.open('https://www.example.com');</script>";
echo "<script type='text/javascript'>window.location = 'https://www.google.com';</script>";
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.