简体   繁体   中英

How can i Redirect Chrome/Firefox Extension with same opened tab if we click on same URL again?

I'm trying to create Firefox extension to redirect to new tab when clicked on any URL or button and also to Redirect with same opened tab if we click on same URL again

Example: If i click on Link tag, its opens to new tab using window.open('https://example.com', 'child-window');

I want to redirect to the same tab if already have open previously else it should open in new tab.

U can create your Own window using window.open and check using if and else

<body>

<button onclick="openRequestedPopup('https://stackoverflow.com/')">Home</button>

<button onclick="openRequestedPopup('https://stackoverflow.com/questions/tagged/javascript')">Your Question </button>

 <script>
var pre = '';
function openRequestedPopup(url) {
    if (pre !== url) {
        myWindow = window.open(url, "Open", 'left=100,top=100,width=320,height=320');
        pre = url
    }
    else if (myWindow.closed) {
        pre = ''
        openRequestedPopup(url)

    }
    else {
        myWindow.focus();
    }
}
  </script>
</body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM