JQuery - On Click image open separate window

帅比萌擦擦* 提交于 2019-12-04 11:27:12

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','',''); 
});

Use :

target="_blank" 

in your a tag.

If you want to follow jquery then use :

$('#imagelink').click(function() {
     var loc = $(this).attr("href");
     window.open(loc, '_blank');
});

Just add the following in the head section of your HTML.

<base target='_blank' />

If you want to open only the links of a particular section of your page then use th e following code

$('#my-Content a[href^="http://"]').attr("target", "_blank");

Here #my-Content is the id of the section in which your links are present. This is for the anchor tags, but it works same with images too.

according to your problem you just need a

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

even after appending this attribut you don't need explicit click function for it. you are attaching a click function it will open in popup window, some browser or you can say browser setting should be enable for popup. but target='_blank' is enough to open a image in new tab. personally i don't recommend click function if you are providing a link in href.

but because you are newbie for your reference their are more attribute for anchor. that will help you in future.

_blank  Load in a new window
_self   Load in the same frame as it was clicked
_parent Load in the parent frameset
_top    Load in the full body of the window
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!