target Blank right in the URL

Asked

Viewed 3,616 times

-1

On my site I have a floating button that has an image and allows me to put a URL, but does not have the option to open in a new tab. You only have space for the URL.

I wonder if it has how to do the function target=_blank direct in the URL, type www.meusite.com.br/contato=_blank

This way, even without having the manual option to open in a new tab, I could put the target=_blank right in the URL and open in a new tab when clicked on this link.

Is there such a thing?

  • Can it be with Javascript? There are a multitude of ways to do using Js...

  • 1

    Try to insert: javascript: window.open('pagina.html', '_blank')

2 answers

0

The short answer is no. This is not possible because a URL is requested through the navigation bar the browser makes a GET and your page is reloaded completely. Which means that for the browser is already a "new page".

What you want to do is open a new page from your current page. This can be done using the html 'a' tag:

<a href="https://www.exmaple.com" target="_blank">example</a>

or dynamically with javascript

window.open('http://example.com', '_blank');

0

Right in the url will not have how. The only possible way would be to insert a javascript code on your page. For example, if you add the code below, every time you click on any element of your page document that it’s an ant a, it will open the link in a new tab.

$(document).on('click', 'a', function(e){ e.preventDefault(); var url = $(this).attr('href'); window.open(url, '_blank'); });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.