Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using window.open(), if the new window freeze so too does the parent

Pretty simple question, really. I've looked everywhere for someone with the exact issue I'm having with no luck...

In tab "A" I call window.open(). The new tab (tab "B") begins to load and its script contains some ajax. The ajax call it makes takes a very long time (this is intentional for now as I am attempting to handle a lengthy ajax call). When tab "B" freezes after a little more than 10 seconds so too does tab "A".

I've tried calling window.open("url", "_blank"); as well as window.open("url"); and neither seems to solve the problem.

To make things more confusing I tried the experiment such that tab "B" opens, ajax doesn't timeout and everything works fine. Then I change the URL parameters in tab "B" (this is what sends database parameters through ajax and is the cause of the lengthy request) and when it times out as expected it still freezes window "A".

I'm sure I'm missing something. What does tab "B" have to do with tab "A" after the window.open() call has completed. I don't understand how they are still tied to each other. While all of this is going on other tabs work just fine.

For the record I'm using Chrome on a Mac but saw a similar "quantum entanglement," let's call it, in Safari as well.

Also, both pages use the DataTables jQuery plugin. It's in the API that the ajax calls are being made. I can't imagine how DataTables could be the culprit here, though...

Any ideas, SO community???

Thanks, in advance!

like image 572
John Carrell Avatar asked Jan 22 '16 23:01

John Carrell


People also ask

Does window open create a new session?

When you open a page in a new tab or window, the web browser creates a new session. If you open multiple tabs or windows with the same URL, the web browser creates a separate sessionStorage for each tab or window.

Which method will open a new window?

The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.

What does window open return?

When window. open() returns, the window always contains about:blank . The actual fetching of the URL is deferred and starts after the current script block finishes executing. The window creation and the loading of the referenced resource are done asynchronously.


2 Answers

That's because the new window is opened in the same process with the opener window.

To cause a link to open in a separate process from your web page, just add rel="noreferrer" and target="_blank" as attributes to the tag, and then point it at a URL on a different domain name. For example: <a href="http://www.google.com" rel="noreferrer" target="_blank">Google</a>

source: https://blog.chromium.org/2009/12/links-that-open-in-new-processes.html

like image 182
Sergei Vavilov Avatar answered Sep 23 '22 21:09

Sergei Vavilov


According to the documentation: (https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Window_features) window.open() currently supports features. Hence we can pass noreferrer or noopener as shown below, which does not freeze or block the parent window.

  window.open(hostUrl, '_blank', 'noreferrer')
like image 26
Sasi Kumar M Avatar answered Sep 22 '22 21:09

Sasi Kumar M