Make that target=“_blank” open always in the same window (not parent window)
I have a form with a target = _blank set up, which works as intended, but I am looking to make the submit form opens on the same window don’t matter how munch submit I do. Does it make sense?, example:
Current behavior is:
- “Parent window” has the form
- When submit the first time a second window is opened, let called “Window Child 1” (until here is fine)
- When I submit the form a second time another child window is loaded (I don’t want this)
Behavior I need:
- When I submit the form the second time I need to get the content on the same window that the first submit used “Window Child 1”. Doing this I look to overwrite the result of the first submit with the second one on the same window.
I did this jsfiddle http://jsfiddle.net/5jmnk1rm/
<form action="/" method="post" id="form1" target="_blank"> <input type="submit" value="Submit" /> </form>
Note: I should not use window.open (due other codes, etc…)
2 Solutions collect form web for “Make that target=“_blank” open always in the same window (not parent window)”
All you need to do is replace _blank with a specific name.
<form action="/" method="post" id="form1" target="foo"> <input type="submit" value="Submit" /> </form>
However you are in for some other complications like, the fact that some browser will open a new tab, instead of a window.
If you need to force opening in a new window regardless of how the user’s browser is configured, you will have no choice but to use window.open. By setting the height and width options, you can force a window to open, not a tab.
You need to provide a name for the window.
_blank is a special case that will always create a new window. If you specify
target="my-form", or some other name, it will reuse the child window.