+3 votes
19.8k views
in Programming by (2.8k points)
How to open a new tab in background while focusing on old window, I want to open a new tab without changing focus on new tab .

Trying this but not working :

<a onclick="window.open(URL); self.focus();>Click</a>

2 Answers

+1 vote
by
edited by

You can use this code :

<a href="https://asktofolks.com/" onclick="window.open('#','_blank');window.open(this.href,'_self');">Open a new tab in background</a>

Here when you will click on this link , this will open a new tab with current page and previous tab will open with new link (https://asktofolks.com/)  .

 

This will help you, in case any query pls let me know.

0
by
Hello,

i have used modal box in current page. with the code as you give, the modal box is not executed in the new tab. why? thanks
0 votes
by

 

just put a link in href attribute which url you want to open on click .

<a href="
https://google.com/" onclick="window.open(URL); self.focus();"><h1>Click</h1></a>

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated