开发者

window.location doesn't work after an AJAX request in Internet Explorer

I am trying to launch a ClickOnce application via a link on a web page. The link has to go to the server to request a transaction GUID before it can launch the application. The code works like this:

function clickHandler() {
    $.post('/gettransactionid.aspx', function(tranId) {
        console.log("BEFORE");
        window.location = "/deploy/Company.Domain.Product.application?" + tranId;
        console.log("AFTER");
    });
    return false;
}

This works perfectly fine in Firefox but in IE it peforms a navigation and doesn't open the clickonce application. The console.log BEFORE and AFTER are shown in the console window in IE8 dev tools. Any help would be appreciated as I've spent 4 hours on this trying to solve it with various hacks!

I have tried:

  • changing the window.location to a window.open. This just fires up a window for a second and fails to launch the application.
  • an alert instead of window.location. This does nothing.
  • Against IE7, IE8 and IE9.
  • Circumventing browser security by adding it to a queue and processing the window.location in the root window context.
  • I have checked gettransactionid.aspx returns the transaction id.
  • Doing it in Firefox - it works fine.

Found the Answer in Microsoft's documentation:

If you have developed a custom Web page that launches a ClickOnce application using Active Scri开发者_运维技巧pting, you may find that the application will not launch on some machines. Internet Explorer contains a setting called Automatic prompting for file downloads, which affects this behavior. This setting is available on the Security Tab in its Options menu that affects this behavior. It is called Automatic prompting for file downloads, and it is listed underneath the Downloads category. The property is set to Enable by default for intranet Web pages, and to Disable by default for Internet Web pages. When this setting is set to Disable, any attempt to activate a ClickOnce application programmatically (for example, by assigning its URL to the document.location property) will be blocked. Under this circumstance, users can launch applications only through a user-initiated download, for example, by clicking a hyperlink set to the application's URL.

Update 1st September 2011: Ironically this has now broken entirely in IE9 thanks to "Automatic prompting for downloads" being removed.


Answer!

If you have developed a custom Web page that launches a ClickOnce application using Active Scripting, you may find that the application will not launch on some machines. Internet Explorer contains a setting called Automatic prompting for file downloads, which affects this behavior. This setting is available on the Security Tab in its Options menu that affects this behavior. It is called Automatic prompting for file downloads, and it is listed underneath the Downloads category. The property is set to Enable by default for intranet Web pages, and to Disable by default for Internet Web pages. When this setting is set to Disable, any attempt to activate a ClickOnce application programmatically (for example, by assigning its URL to the document.location property) will be blocked. Under this circumstance, users can launch applications only through a user-initiated download, for example, by clicking a hyperlink set to the application's URL.

So change the IE security settings to turn automatic prompting for file downloads on.


I have the same problem. One possible solution is changing ajax request from asynchronous to synchronous. If you do that then 'Automatic prompting isn't needed at all.


Try calling setTimeout to perform the navigation a tiny bit later.


You should add a full URL (including http://) for your window.location :-)


I've had the same exact issue a while ago, that was related to the fact that my FQDN had an underscore in it. It is illegal to have an underscore in a FQDN, but only Internet Explorer actually blocks it, while other browsers make it work normally. If you have an underscore, Internet Explorer won't register cookies either...

If that's not your problem, I would suggest to try an e.preventDefault() before the window.location to see what happens.


Try to remove the first slash:

window.location = "deploy/Company.Domain.Product.application?" + tranId;

Maybe IE thinks You are trying to get "deploy" from the root. Anyway I think it's a good practice to use a full url's = No misunderstanding


I agree with Mih, because you can't say to your users to change their browser options. If you use asynchronous request, it might be ok in internet explorer.

You can change your $.post to $.ajax like this:

$.ajax({
  type: 'POST',
  url: url,
  ...
  async:false
});

More info about ajax here: http://api.jquery.com/jQuery.ajax/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜