jQuery-单击图像打开单独的窗口 [英] JQuery - On Click image open separate window

查看:87
本文介绍了jQuery-单击图像打开单独的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击缩略图时,我正在尝试在新选项卡中打开图像,但是即使我尝试了许多不同的解决方案,也没有一个起作用.

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.

我正在发布jquery代码:

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.

我还要发布还包含html的jquery代码(这包含在单独的文件中):

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

感谢您提供任何帮助.

推荐答案

尝试将target用作_blank之类的

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

或者您也可以尝试使用window.open之类的javascript

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

这篇关于jQuery-单击图像打开单独的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆