how not to open new window on clicks after first click on link <a href="abc.jsp" target="_blank">,
I need to open a new window on fir开发者_如何学运维st click on link .
But not to open a new windows on clicks on same link after first click.
Is there any way to solve this problem through html or javascript.
Thanks Jyoti
Replace '_blank' with another string, e.g. 'new_window' (don't use spaces)
On further clicks the link will be opened inside the window opened onto the first click.
See (4.) inside the specification: http://www.w3.org/TR/html4/present/frames.html#h-16.3.2
<script>
var check=0;
function lanuchWindow(page){
if(check==0){
OpenWin = this.open(page);
check=1;
}
}
</script>
html code to call script:
<a href="#" onclick='lanuchWindow('pageURL.htm')'>;Launch Window</a>
This might probably help you... It will launch window for 1st time and set it's variable check to 1 and when again the link is clicked condition turns false and hence no window is launched.
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function Launch(page) {
OpenWin = this.open(page, "mywin", "toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes,width=550,height=250");
}
// End -->
</SCRIPT>
<a href="#" onClick="Launch(...)">click</a>
NOTICE: it won't work if the JS is disabled on Browser. thanks four ur reply, Andy E
<a id="foo" href="url" target="_blank">hello</a>
<script>
// add an onclick handler:
$("#foo").click(function(){
// Now remove the onclick handler so subsequent clicks don't fire it.
$(this).click(function(){});
// And set the target attribute so it opens in current window...
$(this).attr("target", "");
return true;
});
</script>
This is a better option than the ones listed above because it degrades nicely for people who don't have javascript, or want to use their middle mouse button to force opening in a new tab.
精彩评论