Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit the link open only once in new tab?

Tags:

html

In my code, after click on a link I'm open a pdf file in new tab, But after second click if that file is already open then instead of open in new tab I want to redirect to open tab of that file.

My code:

<span style="margin-left:10%;"><a href="image/Eng_Pamphlet.pdf" target="_blank">Broucher</a></span>'

As shown in above tab I'm set the target attribute "_blank", So it opens the link always in new tab. But I want after first time it redirect to first open tab only.

like image 599
Sushant Avatar asked Apr 04 '14 10:04

Sushant


People also ask

How do I stop links from opening in a new tab?

Some links are coded to open in the current tab while others open in a new tab. To take control of this behavior, press Ctrl when you click a link to stay on your current page while opening the link in a new tab in the background.

How do I make a link open in a new tab with one click?

Method 1: Ctrl+Click Simply press and hold the Ctrl key (Cmd on a Mac) and then click the link in your browser. The link will open in a new tab in the background.

Why does a link open in a new tab?

Opening the external links in new tabs allows users to scan the page once, click on all the relevant links and start consuming and sifting information. The user doesn't have to keep going back to the source page to continue scanning for more links to click.

When should a link open in a new tab?

The only time it is recommended that you open a link in a new tab is when opening in the same screen would interrupt a process (e.g. when a user is filling out a form or viewing a video). Linking in the same tab or screen in these situations could cause the user to lose the work they've done or have to start over.


2 Answers

Use target="_new" instead. This will open the link in the same tab

Edit:

_new is not really the best way to do this, as noted in the comment below by Chankey. You can just create a 'custom' value for the target attribute that will allow the link to only open in a specific tab.

http://jsfiddle.net/GTr7L/ -> example

like image 63
Alex Avatar answered Sep 20 '22 20:09

Alex


just assign a custom name to your target tab, so all the links will be redirected to your custom tab

<span style="margin-left:10%;"><a href="image/Eng_Pamphlet.pdf" target="myPDFTabAndEveryTimeThisOne">Broucher</a></span>'

(if you use "_new" another standard "_new" link will overwrite your pdf tab).

like image 40
MrPk Avatar answered Sep 22 '22 20:09

MrPk