Javascript-how does one click link A in the pop-up window X and click link B to continue opening in the pop-up window X (refresh?

Source: Internet
Author: User
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 ;});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.