I am writing code to download a PDF file using window.open()
. I am passing the URL path of the pdf file on a server.
window.open(url, name, "width=910,height=750,scrollbars=yes");
I want to check if the downloading of file is successful or not. What is the return type of window.open()
?
I tried like this
try
{
window.open(url, name, "width=910,height=750,scrollbars=yes");
alert("success");
}
catch(e)
{
alert("failer");
}
When I change the URL to a wrong URL, it shows the same result as a success.
I am writing code to download a PDF file using window.open()
. I am passing the URL path of the pdf file on a server.
window.open(url, name, "width=910,height=750,scrollbars=yes");
I want to check if the downloading of file is successful or not. What is the return type of window.open()
?
I tried like this
try
{
window.open(url, name, "width=910,height=750,scrollbars=yes");
alert("success");
}
catch(e)
{
alert("failer");
}
When I change the URL to a wrong URL, it shows the same result as a success.
Share Improve this question edited Jul 21, 2011 at 14:25 Gilles 'SO- stop being evil' 108k38 gold badges215 silver badges260 bronze badges asked Jul 21, 2011 at 14:09 Bhoomin yadavBhoomin yadav 611 gold badge1 silver badge3 bronze badges 1-
you don't check any return value.
open()
returns either awindow reference
ornull
. – jAndy Commented Jul 21, 2011 at 14:10
2 Answers
Reset to default 8http://www.javascripter/faq/openinga.htm
The return value is the reference to your new window. You can use this reference later, for example, to close this window (winRef.close()), give focus to the window (winRef.focus()) or perform other window manipulations.
Window.open either returns a handle to the new window opened or null, it will not tell you if the page within the window loaded successfully. If you where opening an html page (from the same domain) you could use this to look into the document
var newWin = window.open();
if(newWin == null) {
alert("darn");
}
newWin.document.getElementById("anElement").innerText = "Fish";