X
Tap here to go to the mobile version of the site.
Your Firefox is out of date and may contain a security risk! Upgrade Firefox

Support Forum

run code "window.open(url,...)" in javascript, the action is different according to the time this line of code is executed.

Posted

Hi FireFox support, We are developing a web application with javascript, we use firefox as our default browser for our users.

Now we met a problem when we use window.open in our application.

In our application, we need to open new page in a new browser tab, we used code : window.open('http://ourUrl.com', '_blank');

The action of the browser is different according when this line of code is executed.

situation1: user clicked a button, the click event will trigger our js function, in this function, execute this line of code directly, then the browser may open the page in a new browser tab. (this is what we wanted.)

situation2: user clicked a button, we firstly submit the data on page to our server, and in the callback function, we execute this line of code, it may pop an independent new window without tool bar.(this is not what we wanted).

I don't understand why the action of browser is different, can you help to explain? Thanks.

Chosen solution

When the thread started, were you really running Firefox 11? Perhaps it changed between Firefox 11 (March 2012) and Firefox 19 (March 2013). You could install an old version if you were really curious. To avoid disturbing your main installation, you can use the unofficial "Portable" edition for testing. http://sourceforge.net/projects/portableapps/files/Mozilla%20Firefox%2C%20Portable%20Ed./

Read this answer in context 0

Additional System Details

Installed Plug-ins

  • Shockwave Flash 11.6 r602
  • Next Generation Java Plug-in 10.15.2 for Mozilla browsers
  • NPRuntime Script Plug-in Library for Java(TM) Deploy
  • Google Update
  • Alipay Security Control
  • HttpWatch Basic - HTTP Viewer for Firefox
  • npalicdo
  • npaliedit
  • iTrusPTA&XEnroll hwPTA,IEnroll,UKeyInstalls for FireFox,version=1.0.0.2
  • 4.0.60129.0
  • Adobe PDF Plug-In For Firefox and Netscape 10.0.0
  • Adobe Shockwave for Director Netscape plug-in, version 11.5.9.615

Application

  • User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0

More Information

{
"application": {
"name": "Firefox",
"version": "11.0",
"userAgent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0",
"supportURL": "http://support.mozilla.com/1/firefox/11.0/WINNT/en-US/"
},
"modifiedPreferences": {
"accessibility.typeaheadfind.flashBar": 0,
"browser.cache.disk.smart_size.first_run": false,
"browser.cache.disk.smart_size_cached_value": 921600,
"browser.cache.disk.capacity": 1048576,
"browser.display.background_color": "#C0C0C0",
"browser.display.use_system_colors": true,
"browser.places.smartBookmarksVersion": 2,
"browser.privatebrowsing.autostart": true,
"browser.startup.homepage": "http://i2home/default.aspx",
"browser.startup.homepage_override.buildID": "20120312181643",
"browser.startup.homepage_override.mstone": "rv:11.0",
"dom.ipc.plugins.enabled.nphttpwatchff.dll": false,
"extensions.lastAppVersion": "11.0",
"font.internaluseonly.changed": true,
"gfx.blacklist.webgl.opengl": 5,
"gfx.blacklist.layers.opengl": 5,
"network.cookie.prefsMigrated": true,
"places.history.expiration.transient_current_max_pages": 104858,
"places.database.lastMaintenance": 1361871687,
"privacy.sanitize.timeSpan": 0,
"privacy.cpd.siteSettings": true,
"privacy.sanitize.migrateFx3Prefs": true,
"privacy.cpd.offlineApps": true,
"security.warn_viewing_mixed": false
},
"graphics": "Troubleshoot data provider failed: graphics\n[Exception... \"Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIDOMParser.parseFromString]\" nsresult: \"0x80004001 (NS_ERROR_NOT_IMPLEMENTED)\" location: \"JS frame :: chrome://troubleshooter/content/Troubleshoot.jsm :: graphics :: line 296\" data: no]",
"javaScript": "Troubleshoot data provider failed: javaScript\nTypeError: winEnumer.getNext().QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).isIncrementalGCEnabled is not a function",
"accessibility": {
"isActive": false
},
"libraryVersions": "Troubleshoot data provider failed: libraryVersions\nTypeError: Cc['@mozilla.org/security/nssversion;1'] is undefined",
"userJS": {
"exists": false
},
"extensions": [
{
"name": "Troubleshooter",
"version": "1.0a",
"isActive": true,
"id": "troubleshooter@mozilla.org"
},
{
"name": "FiddlerHook",
"version": "2.4.1.1",
"isActive": false,
"id": "fiddlerhook@fiddler2.com"
},
{
"name": "Firebug",
"version": "1.9.2",
"isActive": false,
"id": "firebug@software.joehewitt.com"
},
{
"name": "Firecookie",
"version": "1.4",
"isActive": false,
"id": "firecookie@janodvarko.cz"
},
{
"name": "HttpWatch Basic Edition",
"version": "8.5.5",
"isActive": false,
"id": "{1E2593B2-E106-4697-BCE7-A9D30DE05D73}"
},
{
"name": "Java Console",
"version": "6.0.35",
"isActive": false,
"id": "{CAFEEFAC-0016-0000-0035-ABCDEFFEDCBA}"
},
{
"name": "Java Console",
"version": "6.0.37",
"isActive": false,
"id": "{CAFEEFAC-0016-0000-0037-ABCDEFFEDCBA}"
},
{
"name": "Symantec Vulnerability Protection",
"version": "11.3.0.9 - 3",
"isActive": false,
"id": "{BBDA0591-3099-440a-AA10-41764D9DB4DB}"
},
{
"name": "Web Developer",
"version": "1.2.2",
"isActive": false,
"id": "{c45c406e-ab73-11d8-be73-000a95be3b12}"
}
]
}

jscher2000
  • Top 10 Contributor
2375 solutions 21032 answers

Helpful Reply

Assuming you are not navigating away from the page, I would expect the same exact results from window.open() in both situations.

https://developer.mozilla.org/en-US/docs/DOM/window.open

Is it possible to post a test case demonstrating the problem?

jscher2000
  • Top 10 Contributor
2375 solutions 21032 answers

Also, I don't know why you are posting with Firefox 11, but make sure you test with Firefox 19.0.2 in case this is a solved bug.

Helpful Reply

Hi jscher20000, the case used in our project is complex, so I made a test, there is no way to attach the attachment here, so I have to pasted the code in the end

I used requirejs to require a js file, and in the callback function I called function window.open(url,'_blank')

I tested them in different browsers, In firefox, click the button 'indirectly' it will open this window in a new tab.

in Chrome, click button "indirectly", it will open a new window instead of a new tab. but if click button "directly" it will open a new tab.

I just don't understand when browser will open a new window, and when opens new tab.


the handler of the "indirectly" and "directly" buttons is written as follows:

clickIndirectly=function(){
   require(['./js/testwindowopen/in.js'],function(){
   window.open('http://google.com','_blank');
  })
}

clickDirectly = function(){
   window.open('http://google.com','_blank');
}

Modified by cor-el

jscher2000
  • Top 10 Contributor
2375 solutions 21032 answers

What does require() do with the callback function that is different from straight JavaScript?

Question owner

require is a javascript framework, in the function:

clickIndirectly=function(){

  require(['./js/testwindowopen/in.js'],function(){
        window.open('http://google.com','_blank');
 })

}

when the function is called, browser will get a javascript file from server via url "./js/testwindowopen/in.js" after the js is loaded ,the call back function :

     function(){
            window.open('http://google.com','_blank');
     }

will be called.

jscher2000
  • Top 10 Contributor
2375 solutions 21032 answers

I see that part, but requireJS appears to be executing the function in a different way. Does your JS library replace the standard window.open function? Is there a change in context such as window referring to an iframe?

Question owner

Hi jscher20000,

I checked the source code of requireJS and our own code, there is no replacement of the standard window.open function, and there is no change of context by our code such as using iframe. the only difference is the place where window.open is called.

Is there any security consideration of the browser when open a link by JS? Or the context is different between the two situations?

jscher2000
  • Top 10 Contributor
2375 solutions 21032 answers

What if you change it to something like this:

clickIndirectly=function(){
  require(['./js/testwindowopen/in.js'],function(){
    clickDirectly;
  })
}

Question owner

it still opens the link in new window.

jscher2000
  • Top 10 Contributor
2375 solutions 21032 answers

it still opens the link in new window.

Yes, that is expected because the target of window.open() is _blank. It still has different toolbars?

Question owner

Hi jscher20000,

What I mean is that it opens the new page in new window, the window has no tool bar. What I expect is open the window in a new browser tab.

jscher2000
  • Top 10 Contributor
2375 solutions 21032 answers

Sorry, but I think you need someone who understands the requirejs library to explain why window.open() works differently when called from the callback.

Question owner

Thanks jscher20000,

this problem has no relationship with require js, I used require js just as a example,

before we involve requirejs in our project, we submit data to server by AJAX, and in the callback function, we use window.open, the browser will open new window too.

jscher2000
  • Top 10 Contributor
2375 solutions 21032 answers

Okay, that is simpler to understand. Your script submits data to a server and does something with the response and then uses window.open(). What result do you get in my test page?

http://www.jeffersonscher.com/res/xhr_win_open.php

Question owner

Hi jscher20000,

Open your test page in firefox, both links opens the new page in new browser tabs, it seems firefox has fixed this problem, I tested in our own application, it also acts as we expected.

But in chrome, it still opens new window, it seems to be a bug of chrome, I will report this bug to them.

Thank you for your reply and your time for supporting this issue.

jscher2000
  • Top 10 Contributor
2375 solutions 21032 answers

Really, after all that, it's a Chrome problem?!

It appears you're out of luck in Chrome unless something has changed recently:

http://stackoverflow.com/questions/11999837/force-window-open-to-create-new-tab-in-chrome

http://stackoverflow.com/questions/9864747/new-window-doesnt-open-as-tab-in-chrome

Question owner

Thanks jscher20000,

Is this problem fixed in firefox recently? I remember that I met it recently, but I can not reproduce it now.

jscher2000
  • Top 10 Contributor
2375 solutions 21032 answers

Chosen Solution

When the thread started, were you really running Firefox 11? Perhaps it changed between Firefox 11 (March 2012) and Firefox 19 (March 2013). You could install an old version if you were really curious. To avoid disturbing your main installation, you can use the unofficial "Portable" edition for testing. http://sourceforge.net/projects/portableapps/files/Mozilla%20Firefox%2C%20Portable%20Ed./