Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery - On Click image open separate window

Tags:

jquery

onclick

I am trying to open an image in a new tab when user clicks on the thumbnail, but even though I've tried many different solutions none of them worked.

I am posting jquery code:

$('#imagelink').click(function() {

     //location.href = $('#imagelink').attr("href"); //It is correct!
    // window.location.href = this.id + '.html'; //It is correct!
  //  window.open($('#imagelink').attr("href"), '_blank');
  //  $.winOpen($('#imagelink').attr("href"), "windowName", { fullscreen: "no", height: "600px", toolbar:    1, width: 600 }); //It is correct!
     window.location = $.myURL("index", $(this).attr("href"));//It is correct!

    });

As you can see I've tried all of the above five aspects and all of them open the image in the same tab which is not what I desire.

I am posting also the jquery code that includes also the html (this is included in separate file):

new_span.append('<a id="imagelink" href="'+ new.link +'"><img src="' + new.url +'" height=50px width="50px"  /></a>');

Any kind of help is appreciated.

like image 368
user2008973 Avatar asked Dec 12 '22 10:12

user2008973


1 Answers

Try with target as _blank like

new_span.append('<a id="imagelink" href="'+ new.link +'" target="_blank"><img src="' + new.url +'" height=50px width="50px"  /></a>');

Or you can also try with javascript using window.open like

$('#imagelink').click(function() {
    var URL = $.myURL("index", $(this).attr("href"));
    window.open(URL,'_blank','',''); 
});
like image 63
Gautam3164 Avatar answered Jan 08 '23 07:01

Gautam3164