Javascript 在新选项卡中单击链接到URL时使用jquery生成图像
我已经尝试了很多方法来实现这一点,我基本上是想让lightbox照片显示出来(它就是这样做的),当点击时,会打开一个带有指定URL的新选项卡。 我试图在新选项卡中链接到url的图像是“images/ad1.jpg”,这在代码中。请告诉我正确的代码和方式,它需要输入,所以我可以这样做。我非常感谢大家在这方面的支持和stackoverflow的伟大社区。多谢各位Javascript 在新选项卡中单击链接到URL时使用jquery生成图像,javascript,jquery,Javascript,Jquery,我已经尝试了很多方法来实现这一点,我基本上是想让lightbox照片显示出来(它就是这样做的),当点击时,会打开一个带有指定URL的新选项卡。 我试图在新选项卡中链接到url的图像是“images/ad1.jpg”,这在代码中。请告诉我正确的代码和方式,它需要输入,所以我可以这样做。我非常感谢大家在这方面的支持和stackoverflow的伟大社区。多谢各位 (function($){ $(window).load(function(){ if(jQuer
(function($){
$(window).load(function(){
if(jQuery.isFunction(jQuery.fn.prettyPhoto)) {
$.prettyPhoto.open(
"images/ad1.jpg", // Image to be opened
"title", // Title of the pop-up
"desc." // The description
);
setTimeout(function() {
$.prettyPhoto.close();
}, 10000); // autoclose after 10 seconds
} else {
console.log("PrettyPhoto is not defined."); // log this message
}
});
})(jQuery);
您应该将jquery.prettyTo.js修改为
$pp_pic_holder.find('.pp_previous, .pp_arrow_previous').bind('click',function(){
$.prettyPhoto.changePage('previous');
return false;
});
$pp_pic_holder.find('.pp_next, .pp_arrow_next').bind('click',function(){
$.prettyPhoto.changePage('next');
return false;
});
到
$pp_pic_holder.find('.pp_arrow_previous').bind('click',function(){
$.prettyPhoto.changePage('previous');
return false;
});
$pp_pic_holder.find('.pp_arrow_next').bind('click',function(){
$.prettyPhoto.changePage('next');
return false;
});
$(document.body).on("click", "#fullResImage", function(){
window.open($(this).attr("src"));
})
我希望它能起作用。这个库有一个
图像标记
选项,使用它可以避免javascript解决方案
在执行以下操作时,在image\u标记
选项中添加一个带有target=“\u blank”
的链接
image_markup: '<a href="{path}" target="_blank"><img id="fullResImage" src="{path}" /></a>'
仅供参考:您在函数调用中将
$
定义为jQuery
,然后在代码中将其称为jQuery
。虽然这确实有效,但它有点违背了将其作为$
传递的目的。下面的任一解决方案对您有效吗?有什么反馈吗?
$("a[rel^='prettyPhoto']").prettyPhoto({image_markup: '<a href="{path}" target="_blank"><img id="fullResImage" src="{path}" /></a>'});
$(document.body).on('click', '#fullResImage', function(){
window.open(this.src, '_blank');
});