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
Related
So currently my website works like this; you post an update and through iframe your update gets added to the database and then shown in a list below. But the problem is that when you clicked "Submit" the text you wrote is still shown in the textarea because the website doesn't update completely. I have tried to have "onsubmit" and "onclick" but both remove the content of the textarea before it gets added to the database so it displays an empty message.
What should I do in order to delay it just a second or how do I make it wait for the iframe to "send" data to my PHP-script?
Give your textarea an id and supposing that iframe is an element of the page that contains the textarea you have done the following in the iframe page:
<?php
//code should be done after db add
?>
<script>
o = parent.document.getElementById('textareaID');
o.value = '';
</script>
<?php
//the end of code or something else
?>
You are able to see those demos on jsbin:
http://jsbin.com/ulOyiVo/1 The page with iframe. Supply the textarea with any text and then click on simulate submit link
http://jsbin.com/EyuBeLo/1/ The iframe page
If your only problem is to have a delayed response, you could trigger a setTimeout function to your onClick, with the given setTimeout:
setTimeout(
function() {
alert('hello');
},1250 //in milliseconds
);
You can define a click or a submit event using jQuery and send a request to your server. You can handle the event when the server responded using a callback. In that callback you need to do whatever it is needed to do. Using setTimeout in this case is an unnecessary hack. You will either set up a big time to wait harming the user experience or in case the page responds later than the specified time your page will work unexpectedly. So, instead of that try defining an event.
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
I have been on this site all day and can't seem to find what I need - no duplicate post intended.
I have a form containing a link which calls a modal popup containing a different form.
###### PARENT PAGE #############
<form...>
...
link
...
</form>
**** MODAL POPUP ****
<form...>
...
<input type="submit" />
</form>
**** END MODAL POPUP ****
### END PARENT PAGE #############
When I submit the form in the modal popup, the parent page is refreshed to show the updated info in the corresponding section of the page; except that the first form is not submitted and when the page refreshes to update the necessary section, the contents of the first form is lost.
I have tried using ajax to refresh only the necessary section of the page but that doesn't work as the sections that need refreshing use php variables with contents from mysql.
The system does what it needs to do and I don't mind the refresh. But I need a way to keep the user data entered into the first form.
Is it possible to submit the first form at the same time as the second to the same php page or any other way of preserving the user data in the first form on page reload without submitting it.
You cannot do this with pure php. You'll need javascript and write it in a way that when you hit submit on the modal it 'puts' the information back into the parent form.
One way is to make the modal form submit button not an actual submit button.
You might even be able to get away with taking the filled out section dom elements in the modal injected back into the parent form. Some jquery plugins already do this. For example colorbox
Here is a working example using only ONE <form> tag and jquery colorbox. http://jsbin.com/olalam/1/edit
I am not a php developer, so I'll suggest an alternative approach.
Before you refresh the page, you can serialize the form and store the data locally (e.g. in a cookie) then restore the data back into the form. Granted, that will require a bit more JS code, but should get you what you want.
UPDATE: Since you mentioned that you might need a little assistance on the JS front, here is some guidance:
Grab the jquery.cookie plugin here.
Grab the jquery.deserialize plugin here.
Use the following code as a starting point.
.
// the name of the cookie
var cookieName = 'myCookieName';
function beforeSubmit() {
// serialize the form into a variable
var serializedForm = $('#id-of-form').serialize();
// store the serialized form
$.cookie(cookieName, serializedForm, { path: '/' });
}
function afterRefresh() {
// read the cookie
var serializedForm = $.cookie(cookieName);
// de-serialize the form
$('#id-of-form').deserialize(serializedForm, true);
}
HTH
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 know I could use a php include to read the html from a file on the server but how do I write a file to the server once the user clicks to navigate to the next page?
I have a div that is changed by jquery on the 1rst page. I want to read the changed div when the user clicks to go to the 2nd page and write the html from the 1rst page to the 2nd page.
You can use combination of javascript and php code.
jquery
get the value of changed div and place it into a hidden field, wrapped within a form tag and submit the form to the next page
php
and on next page, get your hidden field value from $_post array and display it.
So you have a div that is changed via jQuery:
<div id="something">something here</div>
To access the HTML inside your div,
var myHTML = $('#something').html();
Then Use AJAX to send the value to the second page:
$.ajax({
url: 'secondpage.php',
data: {
'key' : myHTML
}
type: 'post'
});
In secondpage.php, check for $_POST['key'] as follows
if( isset($_POST['key']) ) {
// myHTML was sent successfully
}
Not sure if it's a good idea to do this as users are clicking because it would take a while for the document to get updated, and what if multiple users were trying to access the same page? You can use something called a cronjob, which basically executes PHP from your site's server at a specified time interval. I did this to update my website with my Twitter feed every 10 minutes, but doing it on every click would be too slow. What exactly are you trying to do?
When the user clicks on "go to next page" link, send AJAX request to
some PHP file.
The AJAX request should contain the div html (use
jQuery: $(this).html())
In the php file write the html, and return
information to AJAX (true/false).
When AJAX success go to the next page.