How to Open a Url in a New Tab Using JavaScript or Jquery

Open a URL in a new tab (and not a new window)

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.

jquery - how do I open a URL in a new tab/window when the user clicks on a div with no associated href?

For a new window:

$('#my-div').click(function() {
window.open("http://www.google.com", '_blank');
});

or for a new tab:

$('#my-div').click(function() {
window.open('http://google.com');
});

open new tab(window) by clicking a link in jquery

Try this:

window.open(url, '_blank');

This will open in new tab (if your code is synchronous and in this case it is. in other case it would open a window)

JavaScript open link in new tab instead of popup

You can force the target="_blank" onto an <a> by doing this:

$('.link-tag').click(function() {
$(this).attr('target', '_blank');
});

This could work in some browsers, but as a commenter said, if the user's preference is set to open in X, then it will not be able to force it to open in Y.

Open specific link in new tab on pageload

You can try this:

 var newTab = window.open('http://google.at', '_blank');
newTab.location;

Here is the fiddle: http://jsfiddle.net/70kdacL4/310/

For your specific case:

HTML:

<a id="link" href="http://www.google.at" target="_blank">TestLink</a>

JavaScript:

$(document).ready(function(){
window.setTimeout(function(){
var link = document.getElementById("link").href;
var newTab = window.open(link, '_blank');
}, 5000);
});

Be careful if you use a popup blocker. A popup blocker can prevent the tab from beeing opened.

Here is the fiddle: http://jsfiddle.net/qm9ss6s4/4/

How to open a link in new tab using a tag in javascript and jquery

Using jQuery: (Given that there is an <a> element present)

$(function(){
$('a').attr('target', '_blank').attr('href', 'YOUR_LINK').trigger('click')
});

EDIT

Another case (You have <div> element and you want to append a link inside it);

$(function(){
$('div').append('<a href = "YOUR_LINK" target = "_blank">LINK</a>');
});

JS Jquery - Open a link in a new tab

Use target='_blank' attribute to <a> tag.

var conceptName = jQuery('#pa_analise_objeto').find(":selected").val();
if(conceptName=='sem_revisao'){
jQuery("#displayCustomMsg").html("<p>The model will be <br/>printed automatically <a target='_blank' href='https://LINK.HERE.COM' style='color: #202020;'><u>verificação manual</u></a></p>");
}


Related Topics



Leave a reply



Submit