-1
I currently have a button (print) that performs a Submit in the form (since I need some fields that are in this form). This in turn executes the code that is in the action, where I have the following code:
echo "<script>window.open('".$url."', '_blank');</script>";
Well, if I run the script this way, a new tab is opened in the browser, but the original page occurs an error (indexed variable that does not receive value). To get around this error, I thought to run a header.
Thus remaining:
header('location:../paginaOriginal.php');
echo "<script>window.open('".$url."', '_blank');</script>";
exit;
But when I set the header, the new tab is not opened, simply reload the page.
Button script:
$("#botao1").click(function(){
$("#form").submit();
});
The ideal would be the original page, remain static, because it is a print button. However I need some fields that are in the form of this page and put this data in a layout already ready.
You can give no way out (for example, no
echo
) before the headers, they should be the first thing to be sent by the server. See http://answall.com/questions/4251/erro-do-php-cannot-modify-header-information– bfavaretto
I’m not sure what you’re getting at. It seems like you don’t want the form to be submitted, but at the same time you’re forcing it to be. What error occurs on the original page?
– bfavaretto
Which error appears? ever tried to put an onready to wait for page loading ?
– Isvaldo Fernandes
@bfavaretto, if it were possible to open this new tab with the information I am sending in the $url, it would be ideal, but I could not do it. Performing echo after header, the tab is not opened.
– Felipe FM
The error refers to a variable that has been indexed but receives no value.
– Felipe FM
Edit the question to put exactly what the error message was. I understand that you want to open another tab with this URL, but what do you want to happen with the original page? What is the form for? You need to give more context so we can indicate the best way.
– bfavaretto
@bfavaretto, see if you’re better. I edited the question as you had requested. Thank you.
– Felipe FM
I don’t understand why you submit a form you don’t want submitted! When you submit it, it reloads the page. That’s at least part of the problem.
– bfavaretto
Try to put window.open within $(Document). ready(), so it will run after the page loads
– Isvaldo Fernandes
The
header
(php) runs from the server side.header('location:../paginaOriginal.php');
echo "<script>window.open('".$url."', '_blank');</script>";
will never perform thewindow.open
, because the browser does not render pages with server-side forwarding.– Guilherme Nascimento