I have a form within an iframe on my web page. When the submit button is clicked, the result is viewed in the window that contained my web page.
How do I open the result in new window instead?
Can you adjust the form html itself? <form target="_blank">
Try providing an onclick function like this:
<input type='submit' onclick="this.form.target='_blank'; return true;">
Related
I'm building a guessing game that works with user input. When the user inputs a word and submits, it should be taken to a new webpage with an iframe that contains a google page with the search for the element inputed.
For example, if I submit 'cats', i should be taken to a new webpage with an iframe that contains a google page with the search results for 'cats'
This is what I have now. It goes to said new page, but the iframe is empty. My question is: how do you submit the input to the google page in the iframe and redirect the user to the page at the same time?
<p>Choose search for <em>Player 2</em> to guess.</p>
<form action='https://www.google.com/search' method='get'>
<input name='q' type='text' autofocus autocomplete='off' placeholder='Search'>
<button class='btn btn-primary' type='search'>Search</button>
</form>
Google probably doesn't like this sort of usage. Here is how Chrome's javascript console complains when clicking through from Bing to Google inside an iframe:
"(index):1 Refused to display 'https://www.google.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'."
Other than that, here is something that gets some content into an iframe based on user text input from the outer page:
<html>
<body>
Clue: <input id="userInput" placeholder="Try entering: google" type="text">
<hr>
<iframe id="innerSpace" width="90%" height="90%"></iframe>
<script>
let is = document.getElementById('innerSpace');
let ui = document.getElementById('userInput');
ui.addEventListener('change', searchFor);
function searchFor() {
// generates an error page:
// `https://www.google.com/search/?q=${query}`;
// this seems to generate some content:
let query = encodeURIComponent(ui.value);
is.src = `https://www.bing.com/search/?q=${query}`;
}
</script>
</body>
</html>
I am using POST in an HTML form to POST large number of arguments.
I wrote something like this:
<form action="get_status_aisleid.html" method="POST">
<input type="hidden" name="aisleId" value=<% $aisle_id %> />
<input type="hidden" name="enter code heretype" value="verified" />
<input type="hidden" name="value" value=<% $values[1]%> />
<a href="#" onclick="this.parentNode.submit()">
<% $verifiedbaySize %>
</a>
</form>
Everything works fine, if I click on a link in the same window.
But if I right click and open it in a new tab, then my new file (which is doing some operations on arguments passed and then downloading a file) is not called. Instead, the same page is refreshed.
Can someone please suggest something?
Right clicking an opening in a new window will always follow the link (i.e. href="#" meaning "Go to the top of the page". The JavaScript won't run.
No built in control of the browser will submit a form while giving the user the option to choose if it should be in the same or a new window.
This isn't normally a useful choice anyway - opening in a new window is something usually done when the user intends to return to the current page to pick up where they left off, and a form is not something normally presented in the middle of another task.
The closet you could come would be to add a second JavaScript triggered control that sets the target attribute of the form to _blank before triggering submission.
I want to open pdf on another tab/window after click on button.
I tried to set onclick="winodw.location.href" but it still open in same page/window.
Following is my code.
<input type="button" value="Report" onclick="location.href='showpdf?&name=${Name}'">
Any inputs
use target="_blank" to open in a new tab
Change your input button for:
<input type="button" value="Report" onclick="window.open('showpdf?&name=${Name}','_blank')">
The difference is that "window.open" will open a new window and "window.location.href" will redirect the page.
What I'm trying to do is create a simple form with a dropdown list and a submit button. Upon selecting an option from the dropdown list, the user clicks the submit button and a popup window opens that allows them to view more info about the option they selected.
Right now I simply have:
<form action="example.php" method="post" target="_blank">
<select size="7" name="identifier" style="width: 100%;">
<option>
Options....
</option>
</select>
</form>
Now this does 'work' as is in that when the user selects an option and presses submit, it opens a new window with the selected option post data passed along. However I would like it specifically to open a smaller popup window with a size I can define rather than a whole new window. I'm also aware target=_blank is deprecated so I'm wondering what would be the preferred way to achieve this now?
Here is the link that may be solve your problem (stackoverflow Link) : how to show popup if select "option" in "select" dropdown using javascript?
Try this
<form action="example.php" method="post" target='popup' onsubmit="window.open('','popup','width=700,height=400,left=200,top=200,scrollbars=1')">
Or add this code to your submit button :
onclick="window.open('','popup','width=700,height=400,left=200,top=200,scrollbars=1')"
onsubmit call a javascript function.
in that function get all the values you need to pass
e.g. var myelementval = document.getElementById('myelement')
then use
window.open('mywindow.php?myelement='+myelementval,"mypopupname","width=500,height=400,resizable=yes,top=100,left=200,scrollbars=yes"
.........
I have one html page, with a form on it. When the user posts the form, I want the form receiving the response to automatically open up the URL passed by the post in a new browser window.
Basically the URL is passed to the the other page, which in turn opens the URL in a new window then displays another form.
Thanks in advance.
Cheers
Shane
Add target="_blank" attribute to the <form>.
<form action="http://google.com/search" target="_blank">
<input type="text" name="q" />
<input type="submit" />
</form>
This will show the response in a new (blank) window. Note that this happens before the HTML page is loaded (it wouldn't make much sense otherwise).