Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

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

like image 944
Deleted Avatar asked Mar 14 '11 13:03

Deleted


People also ask

Does Internet Explorer support AJAX?

Browsers that support web apps using Ajax:Microsoft Internet Explorer (IE) for Windows version 5.0 and above, with ActiveX enabled.

How do I open a pop up window in AJAX?

Just copy your code you used to open the modal by click, no ? What kind of "modal" window you want to open. Can you provide the code you use on click? "am able to open popup/modal box on a click of a button" success: function (returndata) { $("button").

What triggers AJAX success?

AJAX success is a global event. Global events are triggered on the document to call any handlers who may be listening. The ajaxSuccess event is only called if the request is successful. It is essentially a type function that's called when a request proceeds.

Is it true that with help of AJAX we can request the data from server without reloading the entire page?

AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.


2 Answers

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.

like image 72
Deleted Avatar answered Oct 14 '22 12:10

Deleted


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.

like image 40
Mih Avatar answered Oct 14 '22 13:10

Mih