There are a lot of links. clicking a link will pop up. How to click different links and always open them in the same pop-up window instead of popping up a new window every time. The following code can only pop up a new window every time. {Code...} has many links. clicking a link will pop up a window. How to click different links and always open them in the same pop-up window, instead of opening a new window every time.
The following code can only pop up a new window every time.
$('a').click(function(){ window.open(this.href, ""); return false;});
Reply content:
There are a lot of links. clicking a link will pop up. How to click different links and always open them in the same pop-up window instead of popping up a new window every time.
The following code can only pop up a new window every 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;});
Press F12 now to execute the code and click the link to try.
Update: If the pop-up window is closed, open it again
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 js? In this way, many browsers will block it by default.
It is opened in the current window by default.
Code:
$ ('A '). click (function () {location. href = this. href; // You can move back to the current page // or location. replace (this. href) // cannot roll back to the current page. return false ;});