JavaScript-How to implement click Link A pop-up window x, click on link B to continue in the pop-up X (refresh) open?

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