I know that there are at least two other similar questions, but they do not help me.
I have textarea with tinymce where user writes his text. Then there is a button "PDF" that should create pdf and open it in new tab. The content of pdf is the content in tinymce.
When user click on button, the form is submitted to index.php action. Then index.php gathers information from $_POST variable and creates pdf.
I cannot get it to open in new tab as a normal link.
I tried it in different ways.
1) I can open PDF in the same tab, but this is not what I need. This line opens my pdf on the same tab:
$dompdf->stream('document.pdf',array('Attachment'=>0));
2) I can open it in new window, but then browser warns that this is pop-up. Client doesn't want it. Also another problem with this is that pdf is stored on server. I do not want it (pop-up warning is more important). Here is my code:
$output = $dompdf->output();
file_put_contents('document.pdf', $output); //save pdf on server
//opens generated pdf in new window, but this creates warning for popup
echo '<script type="text/javascript" language="javascript">
window.open("http://modeles-de-lettres.org/test/saved_pdf.pdf", "_blank");
</script>';
I have read those:
1) Open PDF in a new tab using dompdf
This suggests: "As far as opening in a new tab. That depends on how you are generating the PDF. But the simplest way it to provide a link with a target attribute." I think this means that I have
<a href="my.pdf" target="blank"
or
<a href="my.php" target="blank"
But this does not work for me, because I should POST my form to get data from pdf.
2) generate the pdf on newtab in dompdf
This is something that I have implemented before (I did it without sessions), but it creats warning about popups.
You can simply do the following:
<button type="submit" formtarget="_blank">Submit to a new window</button>
formtarget="_blank" attribute will open new tab.
Hope it will help you!
The problem is the order in which you're doing things. You should be opening the new window from a user event, like clicking a button. If a script on a page load event tries to open a window, the browser will presume it's an unwanted popup, since the user hasn't done anything besides navigating to the page.
What could work for you, is adding a target="somewhere_new" attribute to your form tag. This way, the browser would open a new tab since there's no frame/iframe with a name="somewhere_new" attribute, and you wouldn't have to do anything special in the server side, just process the data as you did before using $dompdf->stream('document.pdf',array('Attachment'=>0)); at the end
Related
var form = document.createElement("form");
form.setAttribute("hidden", "true");
form.setAttribute("method", "post");
form.setAttribute("target", "_blank");
form.setAttribute("action", "target.php");
document.body.appendChild(form); // Not entirely sure if this is necessary
form.submit();
return;
I have the above code inside the success of an ajax succes. On success of saving data in the database I send back the said data to be print. I am using FPDF for printing and I have create a template in target.php and I am posting data into that page. So in order to send the data through post I create a form with target set as _blank expecting that when I save another set of data the and print the said data it will open on the previous tab. What is happening now is every time I save data it opens new tab.
What I expect is every time I save and print the data it will open to the previous tab that was opened on first print. Basically I dont want to open new tab every time I print. On first print open new tab then the rest will just load on that tab
I think you need to use _self instead of _blank.
Is there such thing as _black
When I use this one I get the desired functionality I want
I tried a simple demo in w3school like below:
<!DOCTYPE html>
<html>
<body>
<p>Open link in a new window or tab: Visit W3Schools!</p>
</body>
</html>
I want to know if this is a valid target
HELP.. how to Save as pdf in print window in javascript code
How to change this code ?
PDF
I need to make my link open the print window but automatically set the destination to "Save as pdf" instead of "print"?
You cannot do this via javascript.
You can do this:
PDF
In getpdf form pdf file via TCPDF or other
I have a page where if you click on a link, it exposes a div that using ajax displays content from a dbase.
After a user edits this content on the server, I'd like to use PHP to return the user to that page. This is no problem using a redirect
header("location:page.php")
However, when the user comes back to the page, ideally, I'd like to have the content in the div open automatically so the user can immediately see edits without having to find the link to open the div and click on it.
Is this possible, either with something in the url to fire the javascript or alternaively, when you load the page with a certain parameter, triggering javascript to open the div.
The code to open the div is a simple javascript call:
View Content
showDiv just uses ajax to display something from the server using responsetext.
Thanks for any suggestions
header("location:page.php?show=1")
Then in page.php body tag:
<body <?php if($_GET['show']==1) { ?>onload="showDiv()"<?php } ?>>
I need your quick help.
In my web site I have a list of clients with links to their user details.
I used
window.open();return false;
and this opens each profile in new window.
now in the new opening window I have link, which I want to open in another new window/
I tried
window.opener.open();return false;
but it opened in this same window.
How can it be opened in another new window(FF,explorer)??.
I want also to use the above code with Ajax, in my search page.
The problem is, that it also not opening the new window because the link located in the Ajax. how can i open links from Ajax in new window??
Any ideas?
Thanks!!!
Well you can access window.parent from your window object and call a function that will open another window
Use Window.open() in the opened window.
So you have : (1) Page with a link -> (2) opens a popup with a link -> (3) opens another popup
Every link which has to open a popup will call the javascript function window.open. As #Sushil pointed out, if the new window has to look like a regular popup, set width and height to it.
If you want to implement the popups using AJax, use jQuery. Here is a very good example for a simple popup implementation.
Providing height and width to open. this will make sure that new window always open as popup.
window.open(url, 'name', "height=500,width=700"); return false;
Is it possible to open a window from PHP that has predefined content? It's obvious how you can open a window from a javascript link that frames an existing page, or just do a target=_blank from a regular a tag that references an existing page. But I am generating a bit of content, and want that content to be opened in a new link (or streamed to the viewer)--
something like (clearly psuedo code!):
$content = "Hello World. <br />Nice to meet you!";
<a href="#" target="_blank" content=$content>Open up!</a>
Is this possible?
Thanks!
Well, the direct answer to your question is that you can't really do it from PHP directly, because it's the browser that's going to open the window. You can, however, have your page open a window, get the document object, and write to it:
var w = window.open("Surprise", "#");
var d = w.document.open();
d.write("<!DOCTYPE html><html><body>Hello World</body></html>");
d.close();
Instead of the simple string "Hello World" of course your PHP script can put together whatever it wants. Additionally, if desired, the Javascript code itself can dynamically generate the content based on page status, form fields, etc.
Note that you can't guarantee that the new window won't be a new tab, which is no different than what happens with "target" in <a> or <form> tags.
edit — oh also: if you try to use window.open outside of code that's running in response to a "click", browsers will probably think you're trying to show a pop-up ad and will block it.