Is that there are a lot of links, click the link will pop-up window, how to implement a click on different links, always open in the same pop-up window, not every time a new window pops up.
Use the following code only to pop up a new window each time.
$('a').click(function(){ window.open(this.href, ""); return false;});
Reply content:
Is that there are a lot of links, click the link will pop-up window, how to implement a click on different links, always open in the same pop-up window, not every time a new window pops up.
Use the following code only to pop up a new window each time.
$('a').click(function(){ window.open(this.href, ""); return false;});
var x;$('a').click(function(){ if(x){ x.location.href = this.href; } else { x = window.open(this.href, ''); } return false;});
Now press F12, execute the code, and click the link to try it out.
2015-9-6 Update: Reopen if the popup window is closed
var x;$('a').click(function() { if (!x || x.closed || !x.opener) { x = window.open(this.href, ''); } else { x.location.href = this.href; } return false;});
Why use JS? Doing so many browsers will block by default.
the default is to open it in the current window
Code:
$('a').click(function(){ location.href = this.href; //可以后退到当前页 // 或者 location.replace(this.href) // 不可以回退到当前页 return false;});