How to open an image in a new tab by clicking it and locking page without parameter?

Asked

Viewed 1,808 times

1

I’m with the CSE research on my website, and I even asked this question: How to change URL objects via Javascript?, and wanted to know if you have how to create a script that the images of the page open in new tab when they are clicked.

And wanted the user to be redirected to the homepage of the site when the search page was with the parameter ?q= empty (no search).

  • 1

    The more details you give in the question, the easier it is to answer first. But, attention, important details, superfluous details only get in the way.

1 answer

1


To open a new window you can see this response. Deep down you need to use the window.open('url da imagem'), or you can just use the attribute target="_blank" in HTML using in href anchor the image URL:

<a href="http://meudominio.com/minhaimagem.jpg" target="_blank">Texto ou Imagem aqui</a>

To do the redirect can do so (putting inside tags <script></script> preferably in head page:

var query = window.location.search;
if (query == '?q=') window.location.href = "http://answall.com";
  • Blz. You need to have the image ID?

  • @Gustavoponte depends on how HTML is done, and how it redirects. What HTML do you click? It’s an anchor? <a></a>

  • Look, I know that when image results are displayed and the user clicks, instead of opening the image, opens a link. See: https://www.google.com/cse/publicurl?cx=012244706173914607628:ivy1g9qzid0

  • And the "Location.search," actually, the search link is:

  • What about "locarion.search": My website’s search link is: www.site.com/search/? q=search. What do I do?

  • @Gustavoponte put the javascript I gave in the reply inside your page, it will read the URL and do the redirect.. Regarding how to open an image I answered what you asked in the question.

  • 1

    It worked! Thank you, thanks!

  • 1

    Marquei! Thank you!!!

Show 3 more comments

Browser other questions tagged

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