how to close new tab or new window (IE 6) on click of hyperlink
In my application when i click on menu option i开发者_开发知识库t open new tab in FF and new window in IE6, so my requirement is when i click on hyperlink on new open window it close new tab or new window(IE6).
You can use window.close
(MDC link, MSDN link). Provided it's in direct response to a user-initiated action and the window was opened via script, it should close the window.
Update: Re your question below:
I want to add onclick event following syntax
<a id="logout" href="<c:url value='/' />">Logout</a>
how should i modify this line for onclick event.
You have multiple options:
Use the
javascript:
pseudo-protocol in thehref
:<a id="logout" href="javascript:window.close();">Logout</a>
Use an
onclick
attribute:<a id="logout" href="#" onclick="window.close(); return false;">Logout</a>
Hook up your event handler unobtrusively via script:
<a id="logout" href="#">Logout</a> <!-- Elsewhere, probably in a script file you include at the very end of the body tag --> <script> document.getElementById("logout").onclick = function() { window.close(); return false; }; </script>
You can use window.close();
from Javascript to close the current window.
精彩评论