Javascript: Location.Href to Open in New Window/Tab

JavaScript: location.href to open in new window/tab?

window.open(
'https://support.wwf.org.uk/earth_hour/index.php?type=individual',
'_blank' // <- This is what makes it open in a new window.
);

javascript window.location in new tab

I don't think there's a way to do this, unless you're writing a browser extension. You could try using window.open and hoping that the user has their browser set to open new windows in new tabs.

Open window.location.href location in a new window

function onDropownChange(e){
var value = document.getElementById('dropDown').value; switch(value){ case 'A': window.open('https://www.google.com','_blank'); case 'B': window.open('https://stackoverflow.com/','_blank'); }
}
<!DOCTYPE html><html><head> <title>Example</title></head><body>
<select name="example" id="dropDown" onchange="onDropownChange()"> <option value="A">Option A</option> <option value="B">Option B</option></select>
<script>
</script>
</body></html>

window.location.href - Link in new tab

notification.onclick = function() { 
window.open(theLink);
};

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.

window.location open in new tab

make it

$('.go-btn').click(function() {
window.open( $('#my-dropdown').val() );
});

or

$('.go-btn').click(function() {
window.open( $('#my-dropdown').val(), "_newtab" );
});

Cannot open page in a new tab using location.href

You can use the target="_blank" attribute on any regular anchor tag to make sure that the link is opened in a new tab, without using any JavaScript. Note, however, that mailto links are often handled by browsers specially and may just redirect to the system's default mail app without opening a visible tab.

<a id="email" target="_blank" href="mailto:person@example.com?subject=Subject&body=Body">
Email us!
</a>

Edit: It looks as if this method won't work in certain versions of Firefox, due to a bug. (See this answer.)

How to open new tab using onclick="javascript:location.href"?

Why not use window.open .

<a onclick="window.open('website.com' + location.search)"><a/>


Related Topics



Leave a reply



Submit