: Can I POST to a new window that I want to open up? Is this possible? A third party site is running my Drupal module An end user clicks on a link which will: Open up a new window www.mysite.com/redirect.php
Is this possible?
A third party site is running my Drupal module
An end user clicks on a link which will:
Open up a new window mysite.com/redirect.php and POST certain data to this page mysite.com/redirect.php
I've seen the user's browser being redirected, but am not clear on how to do the above.
More posts by @Samaraweera270
1 Comments
Sorted by latest first Latest Oldest Best
If you just want a link that opens a POST-requested page in a new window here are some ideas. However, be aware a POST request can't be bookmarked.
You can make a button that opens a POST-requested page in a new window.
<form method="post" action="http://example.com/example.php"
target="_blank">
<input type="hidden" name="name1" value="value1">
<input type="hidden" name="name2" value="value2">
<input type="submit" value="Open results in a new window">
</form>
If you want it to look like a link, you can make a link with an onClick attribute that submits the form.
<form name="myform" method="post" action="http://example.com/example.php"
target="_blank">
<input type="hidden" name="name1" value="value1">
<input type="hidden" name="name2" value="value2">
</form>
<a href="http://example.com/example.php"
onClick="document.forms['myform'].submit(); return false;">Open results
in a new window</a>
The onClick part submits the form, which opens the POST-requested page in a new window. The return false prevents the browser from also going to the href address in the current window at the same time. If Javascript is disabled or the link is bookmarked, the href address is used as a fallback, but the resulting page won't receive any POST values. This might be confusing or unfriendly for your users if they bookmark the link.
If you want the link to be bookmarkable, investigate if your page can accept GET parameters. If so, then you can make a bookmarkable link.
<a href="http://example.com/example.php?name1=value1&name2=value2"
target="_blank">Open results in a new window</a>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.