How do you change JavaScript code of window.open to not open in a new window?
-
I have a JavaScript file which on form submit, which opens results in a new window. It is using window.open to open in a new window. How do I submit in the same window?
-
Answer:
You don't have to change the behavior of window.open to target the same window, because window.open already supports this option. First you need to give your window a name, then you provide that name to window.open as the second parameter: window.name = Math.random().toString(36); window.open(url, window.name); Alternatively, you can just tell the form to target a named window when it gets submitted: var form = document.createElement("form"); form.action = "/path/on/server"; form.method = "GET"; form.target = window.name = Math.random().toString(36); // add some data fields to the form form.submit(); In both of these examples I've used Math.random().toString(36) as a way of generating random alphanumeric names.
Ben Newman at Quora Visit the source
Other answers
you can create a fake façade for if... window.open = function(url) { if(url) { location.href = url; } return window; } of course if you a url is passed then any subsequent js won't exceute because the new page will load
Howard Rauscher
Related Q & A:
- How to open highcharts in new window?Best solution by Stack Overflow
- How to open a new window in windows form application?Best solution by Stack Overflow
- How do I set my e-mail to alert me when I get a new message?Best solution by Yahoo! Answers
- How do I open up a new folder?Best solution by Yahoo! Answers
- How do you stop Yahoo from opening links in a new window?Best solution by answers.yahoo.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.