最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - what is return type of window.open() in Javascript - Stack Overflow

programmeradmin4浏览0评论

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 a window reference or null. – jAndy Commented Jul 21, 2011 at 14:10
Add a ment  | 

2 Answers 2

Reset to default 8

http://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";
发布评论

评论列表(0)

  1. 暂无评论