开发者

Closing a window

开发者 https://www.devze.com 2023-02-09 03:01 出处:网络
This line is from my JSP file. I opened this page by setting a target attribute in the <a> tag like target =\"_TOP\", but the code below is not working.How can I开发者_如何学运维 close this win

This line is from my JSP file.

I opened this page by setting a target attribute in the <a> tag like target ="_TOP", but the code below is not working. How can I开发者_如何学运维 close this window?

<div><a href="JavaScript:window.close()">click</a></div>


You can only close a window with JavaScript that has been opened with JavaScript. Since you went with an HTML method, this won't work.

However, if you were to re-code so that JavaScript was opening the window instead...

<a href="myurl" onclick="window.open('myurl'); return false;">mylink</a>

Then you could close the resulting window with JavaScript.


  1. target should be _top - this will not pop a NEW window but overwrite the current - is that what you want
  2. try this

    <a href="page.jsp" target="_blank"
    onclick="var w=window.open(this.href,this.target); return w?false:true">pop a new window</a>

or

<a href="page.jsp" target="mywin" 
onclick="var w=window.open(this.href,this.target); return w?false:true">pop a new window</a>

the later you can get the handle:

var w = window.open('','mywin');
if (!w.closed) w.close()
0

精彩评论

暂无评论...
验证码 换一张
取 消