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

php - How to close a pop up window using the anchor's OnClick in javascript? - Stack Overflow

programmeradmin1浏览0评论

I have a php page that opens a pop window. it contains the search results. each result is inside the anchor tags.

I can open a new tab containing the information in the parent window, but somehow the OnClick function does not work. what i want to do is when the user select a link, will open a new tab then the pop up window automatically close. I dont know why the OnClick event is not doing what I want.

<?php
<a href='edit.php?id=$id' target='_blank' onClick='self.close();'>Listq</a>
?>

the code above works but it closes the pop up before opening the new tab. please help. thanks.

I have a php page that opens a pop window. it contains the search results. each result is inside the anchor tags.

I can open a new tab containing the information in the parent window, but somehow the OnClick function does not work. what i want to do is when the user select a link, will open a new tab then the pop up window automatically close. I dont know why the OnClick event is not doing what I want.

<?php
<a href='edit.php?id=$id' target='_blank' onClick='self.close();'>Listq</a>
?>

the code above works but it closes the pop up before opening the new tab. please help. thanks.

Share edited May 28, 2013 at 8:17 sAnS 1,1631 gold badge8 silver badges10 bronze badges asked May 28, 2013 at 8:10 ladybugladybug 652 gold badges3 silver badges10 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 3

Try to close the popup from the new tab on load and not from the popup:

window.opener.close();

Try this:

onClick='setTimeout("self.close();",1)'

Check out this

<a href="#" onclick="closeWin()">Close</a>

    function closeWin()
{
self.close();
}

You can try onmouseup in stead of onclick. And if that fails too you can also do the opening of the popup in the onclick with window.open(). That way your order is maintained.

So it would look like:

<a href='#' onClick="window.open('edit.php?id=$id'); self.close(); return false;">Listq</a>

And get writ of the <?php and ?> tag, or put the anchor in an echo if this is PHP.

发布评论

评论列表(0)

  1. 暂无评论