开发者

window.open no longer works when called in the onunload event handler in IE9

In my web application, I launch a desktop application using a custom url protocol. For example: "fakeproto://" will launch "fakeproto.exe" on your desktop. If you don't know what I'm talking about, read this: Registering an Application to a URL Protocol

I needed a way, though, to make sure "fakeproto.exe" was installed on the user's PC before attempting to launch. It's a bit of a hack, but I got it to work for all the major browsers. IE presented the most problems and had a unique implementation.

In Javascript, I would first try to load the custom url protocol:

window.open('fakeproto://', '_self');

Before this, I actually defined the following onunload event handler:

window.onunload = function()
{
     window.open('help.php', '_self');
}

So if the desktop didn't recognize the custom url protocol, IE would simply leave the current page and go to "webpage cannot be displayed". In this event, the onunload event handler would fire and open help.php instead.

This works great in IE7 & IE8, but once I upgraded to IE9, this no longer works? It goes to "webpage cannot be displayed" instead of help.php.

Using a debugger, the onunload event handler is firing and the code is being executed correctly, but for some reason the window.open call isn't working??? I disabled the pop-up blocker as well, to make sure it wasn't that. No luck.开发者_如何学JAVA

Anyone have any ideas? Anyone hear of IE9 being more strict with window.open? Anyone know of any alternative solutions to the original problem?

BTW, I can get it to work if I open help.php to a new window.

window.onunload = function()
{
     window.open('help.php', '_blank');
}

But this only works if any pop-up blockers are disabled. I would like to avoid using this solution.


Yes, IE9 blocks navigations in the onunload handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜