Crazy Horse
asked on
How to open a new browser tab after executing php script
I am using a php to PDF library to generate a pdf document once a user has submitted data and once a user inserts a record I want another tab to open with the pdf and then redirect the initial page they were on back to the dashboard.
The below doesn't work as I am just redirected to the dashboard and it is code for opening a new window, not tab. It doesn't even open a new window and even if it did, it would probably be blocked by a pop-up blocker.
Any suggestions?
The below doesn't work as I am just redirected to the dashboard and it is code for opening a new window, not tab. It doesn't even open a new window and even if it did, it would probably be blocked by a pop-up blocker.
Any suggestions?
//insert code goes here. After success...
echo "<script type='text/javascript' language='Javascript'>window.open('pdf/examples/pdf.php');</script>";
header("location: dashboard.php");
exit();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In my experience, only the browser user can choose whether a page opens in a new tab or new window. I have never seen any code that could choose between them.
ASKER
Thanks for the suggestions. I did consider forcing a download but I don't really want the user to download them, but more view online only and download if they want to.
You do realize (I hope) that to view the PDF files in your browser you are actually downloading them to a 'temp file' on your computer and opening them locally? That's true even of HTML files. Everything thing you see in your browser is at least for that moment downloaded to your computer.
I don't really want the user to download ...It's not our choice on the server side of things. If you create a document that the client can see, you have created a document that the client has already downloaded before seeing it. At that point it's up to the client to decide whether they want to store the document, delete the document, send the document to Wikileaks, publish the document on another web site, etc.
ASKER
To clear things up, what I meant was that I don't want to force a download as it is unnecessary. I just wanted it to open in a new tab but I can't so I will do what Ray suggested and provide them a link to the document. They are welcome to download the PDF if they want, to a location of their choice by clicking on the default download icon once the PDF is presented to them or they can just print it. That would be easier than going through the temp folder trying to locate it.
My goal was just to get them to print it and issue it but if they want to save them to keep a record then that is fine with me as well.
My goal was just to get them to print it and issue it but if they want to save them to keep a record then that is fine with me as well.
You know most browsers open PDF's in the browser anyway now so you're kinda of fighting against the grain wanting to do it your way
ASKER
I am not actually sure if a temp PDF is downloaded. If you are interested you can try it yourself. I used this:
https://tcpdf.org
You actually go to a .php extension to view the PDF. So, that is different to going to mysite.com/pdf/pdf.pdf
You are actually just going to mysite.com/pdf/pdf.php and being rendered a pdf.
https://tcpdf.org
You actually go to a .php extension to view the PDF. So, that is different to going to mysite.com/pdf/pdf.pdf
You are actually just going to mysite.com/pdf/pdf.php and being rendered a pdf.
ASKER
Or I could be wrong. But it is doing what I want it to do which is take info from my database and show it in PDF format in a webpage.
Even tho its a php page it's still a PDF that is stored locally
I am quite sure that anything at all - web page, image, video, PDF, anything that can be displayed on the client browser has been downloaded and stored on the client computer or device. It has been released into the wild.
Everything thing you see in your browser is at least for that moment downloaded to your computer.
ASKER
But is it stored locally as a pdf or webpage?
PDF as you will have sent PDF headers to tell the browser this is a PDF
Whatever the file is, it is saved in a temp directory and then opened locally. That is the way that web browsers have Always worked. The current location in my Firefox is C:\Documents and Settings\dib2\Local Settings\Application Data\Mozilla\Firefox\Profi les\rouzq6 h0.default -145301728 8171\cache 2\entries and it has 34,915 entries for the last year and a half. It is the browser 'cache'.
ASKER
Haha, that's a lot!
That's just Firefox. I didn't even look at Chrome or SeaMonkey. Or on any of the other computers... Note that every little or large file that gets downloaded is kept in the 'cache'. Files from less than 1KB to 9599 KB.
ASKER