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.
我正在编写使用windows .open()下载PDF文件的代码。我在服务器上传递pdf文件的URL路径。
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()
?
我想检查一下文件的下载是否成功。windows .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.
当我将URL更改为一个错误的URL时,它显示了与成功相同的结果。
2 个解决方案
#1
7
http://www.javascripter.net/faq/openinga.htm
http://www.javascripter.net/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.
返回值是对新窗口的引用。稍后您可以使用这个引用,例如,关闭这个窗口(winRef.close()),将焦点放在窗口(winRef.focus())或执行其他窗口操作。
#2
4
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
窗口。打开或返回打开的新窗口的句柄或null,它不会告诉您窗口内的页面是否已成功加载。如果您打开一个html页面(来自同一个域),您可以使用它来查看文档。
var newWin = window.open();
if(newWin == null) {
alert("darn");
}
newWin.document.getElementById("anElement").innerText = "Fish";
#1
7
http://www.javascripter.net/faq/openinga.htm
http://www.javascripter.net/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.
返回值是对新窗口的引用。稍后您可以使用这个引用,例如,关闭这个窗口(winRef.close()),将焦点放在窗口(winRef.focus())或执行其他窗口操作。
#2
4
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
窗口。打开或返回打开的新窗口的句柄或null,它不会告诉您窗口内的页面是否已成功加载。如果您打开一个html页面(来自同一个域),您可以使用它来查看文档。
var newWin = window.open();
if(newWin == null) {
alert("darn");
}
newWin.document.getElementById("anElement").innerText = "Fish";