How do I open a window from the outside?

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

Was this solution helpful to you?

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:

Just Added Q & A:

Find solution

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.