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

1

I'm with the CSE search on my site, and I even asked that question: How to change URL objects via JavaScript? , and was wondering if you have how to create a script that page images open in a new tab when they are clicked.

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

    
asked by anonymous 03.11.2014 / 15:47

1 answer

1

To open a new window you can see this answer . In the background you need to use window.open('url da imagem') , or you can simply use the target="_blank" attribute in HTML using href anchor the URL of the image:

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

In order to do the redirection, you can do this (by placing within%% tags preferentially on the <script></script> of the page:

var query = window.location.search;
if (query == '?q=') window.location.href = "http://pt.stackoverflow.com";
    
03.11.2014 / 15:56