Force window.open () to create a new tab in chrome

I use window.open to populate a new window with various contents. Mostly reports and stored HTML files from automated processes.

I noticed a very incompatible behavior with Chrome regarding window.open ().

Some of my calls will create a new tab (preferred behavior) and some popups.

var w = window.open('','_new'); w.document.write(page_content); 

page_content is plain HTML from AJAX calls. Reports contain some information in the header, such as the title, icon, and some style sheets.

In IE9, code calls up a new tab instead of a popup, while Chrome flatly refuses to display the content in question on a new tab. Since content is important business data, I cannot post it here. I will answer questions if I can.

I know that some people will say that this behavior is left to the user, but this is an internal business platform. We don’t have time to teach all users how to manage pop-ups, and we just need them to be on a new tab. Heck, even a new window would be preferable to a popup, since you cannot attach a popup in Chrome. Not to mention that none of the pop-up blockers will affect it.

Appreciate any insight.

+23
javascript google-chrome tabs
Aug 17 2018-12-12T00:
source share
4 answers

window.open must be called in a callback that is triggered by a user action (onclick example) so that the page opens in a new tab, and not in the window.

Example:

 $("a.runReport").click(function(evt) { // open a popup within the click handler // this should open in a new tab var popup = window.open("about:blank", "myPopup"); //do some ajax calls $.get("/run/the/report", function(result) { // now write to the popup popup.document.write(result.page_content); // or change the location // popup.location = 'someOtherPage.html'; }); }); 
+39
Jan 31 '13 at 17:48
source share

You can try the following:

 <a href="javascript:openWindow();">open a new tab please</a> <script> function openWindow(){ var w = window.open("about:blank"); w.document.write("heheh new page opened"); } </script> 
+4
Mar 26 '13 at 3:27
source share
 window.open('page.html', '_newtab'); 

Specify "_newtab". This works in IE and FF, and should work in Chrome. But if the user has settings that cannot be opened in a new tab, you cannot do this.

0
Aug 17 2018-12-12T00:
source share

Very simple, to make Chrome open in a new tab, use the onmouseup event

onmouseup="switchMenu(event);"

0
Oct 10 '14 at 17:50
source share



All Articles