开发者

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:

  1. Use the javascript: pseudo-protocol in the href:

    <a id="logout" href="javascript:window.close();">Logout</a>
    
  2. Use an onclick attribute:

    <a id="logout" href="#" onclick="window.close(); return false;">Logout</a>
    
  3. 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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜