Hitting a url better?

113 views Asked by At

I've a ashx handler which outputs the file, when pinged. As of now, I have it working by

window.open('url to ping');

I'm happy with the result. But however I'm interested in a better solution, since a user might have turned on popup blocker, which might result in file not downloading. I can also use jquery ( if that helps )

2

There are 2 answers

3
Yuck On BEST ANSWER

You can simply use window.location = "http://pathtoyourhandler.ashx" instead.

With appropriate Content-Type the browser will stay on the current page and begin downloading the requested file.

6
plalx On

If you do not want a window to open, you could always create a hidden <iframe> that has it's src property set to your link.

We used that work around when simply setting the location did not give the expected result (at least in IE8).

DEMO