I am currently developing a web application where I need to open a popup window to show a report. The problem is that some versions of explorer don’t support the window.open javascript function, so when this is the case I catch the error and open the new url with location.href. Here the code:
try {
window.open(url, "","width=1002,height=700,location=0,menubar=0,scrollbars=1,status=1,resizable=0")
} catch(e) {
location.target = "_blank";
location.href = url;
}
The problem is that the location.target is not working and I would like to know if there is a way to specify the target of the location.href so it can be opened in a new tab.
Say what? Can you provide a reference for that statement? With respect, I think you must be mistaken. This works on IE6 and IE9, for instance.
Most modern browsers won’t let your code use
window.openexcept in direct response to a user event, in order to keep spam pop-ups and such at bay; perhaps that’s what you’re thinking of. As long as you only usewindow.openwhen responding to a user event, you should be fine usingwindow.open— with all versions of IE.There is no way to use
locationto open a new window. Justwindow.openor, of course, the user clicking a link withtarget="_blank".