Hi all, I'm hoping this is the right place for this, but is there a way to something to a URL so that when that URL is linked or embedded somewhere, the link will automatically take them to a new tab?
I am trying to set a link in our top navigation menu on our WordPress site that uses Avada, and I don't have the option to just tell it to open that link in a new tab as a setting. So I was hoping I could set it to do so just by the link itself, but I'm not familiar enough with that to know if it is possible or not. Looking it up myself has only yielded results for "target=_blank" when doing hardcoding on the back end-something that isn't an option with the set up we have (or I'm just not aware of how to go about it).
Any help or advice is appreciated!
How to customize the default content(URL) of a New Tab? - Google Chrome Community
Force all external links into a new tab?
Hyperlinks within Forms - Force Link to Open in Separate Tab
hyperlink - How to open link in a new tab in HTML? - Stack Overflow
Videos
This is a trick,
function openInNewTab(url) {
window.open(url, '_blank').focus();
}
// Or just
window.open(url, '_blank').focus();
In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.
<div onclick="openInNewTab('www.test.com');">Something To Click On</div>
Reference: Open a URL in a new tab using JavaScript
Nothing an author can do can choose to open in a new tab instead of a new window; it is a user preference. (Note that the default user preference in most browsers is for new tabs, so a trivial test on a browser where that preference hasn't been changed will not demonstrate this.)
CSS3 proposed target-new, but the specification was abandoned.
The reverse is not true; by specifying certain window features for the window in the third argument of window.open(), you can trigger a new window when the preference is for tabs.
Set the target attribute of the link to _blank:
<a href="#" target="_blank" rel="noopener noreferrer">Link</a>
For other examples, see here: http://www.w3schools.com/tags/att_a_target.asp
Note
I previously suggested blank instead of _blank because, if used, it'll open a new tab and then use the same tab if the link is clicked again. However, this is only because, as GolezTrol pointed out, it refers to the name a of a frame/window, which would be set and used when the link is pressed again to open it in the same tab.
Security Consideration!
The rel="noopener noreferrer" is to prevent the newly opened tab from being able to modify the original tab maliciously. For more information about this vulnerability read the following articles:
- The target="_blank" vulnerability by example
- External Links using target='_blank'
Use one of these as per your requirements.
Open the linked document in a new window or tab:
<a href="xyz.html" target="_blank"> Link </a>
Open the linked document in the same frame as it was clicked (this is default):
<a href="xyz.html" target="_self"> Link </a>
Open the linked document in the parent frame:
<a href="xyz.html" target="_parent"> Link </a>
Open the linked document in the full body of the window:
<a href="xyz.html" target="_top"> Link </a>
Open the linked document in a named frame:
<a href="xyz.html" target="framename"> Link </a>
See MDN
I am working on rebuilding a very old site which has right clicks disabled so I cant right click links and open links in a new browser tab. Also, CRTL clicking the links has no effect. I need to navigate a few clicks down on some pages and have those pages open on new tabs (and monitors) so that I can cut and paste the old text into new pages that I am developing. Is there any way around this limitation? A browser plug in perhaps?
This old site is so frustrating because hitting the back button doesnt take me back to where I just was, but up a level or two, where the whole navigation began. This is such a frustrating process.
Thank you.
If I get you, you want your link to open the page in another tab.
You may use the target attribute of the link like this :
<a href="somepage.html" target=newtab>text</a>
If you want something you can type in the URL field of the browser, that is a bookmarklet, you may use this :
javascript: window.open('http://www.dystroy.org');
In most browsers, ctrl-click a link do the same thing.
EDIT :
If what you can modify is only the href attribute of the link, you can make this href be like this :
<a href="javascript:window.open('http://www.dystroy.org');" target=_blank>text</a>
If its a hyperlink just add a "target" to the hyperlink with its value as "_blank". Working example:
<a id="termsLink" href="www.someLink.com" target=_blank>
Terms and Conditions</a>
I'm using Opera at work for a very specific purpose - working in MS Business Central through its web app. This means that I'm constantly opening new tabs that need to go to the same starting URL. I almost never need to use the search bar or enter any other URL in a new tab.
So what I'm looking for is the fastest way to open a new browser tab and go to the URL of our on-prem Business Central server. Ideally, a single keyboard shortcut. I've already got it stripped down to the point that I can open a new tab and just click on the only bookmark I have, but it's not quite ideal.
Any suggestions? Unfortunately, simply duplicating the tab I'm leaving won't work, as the way BC handles URLs means that doing this dumps you in a loading screen instead of the place you just left.