2014-08-28 22 views
-1

我已經嘗試了很多事情來獲得這個工作,我基本上試圖讓燈箱照片顯示(它它),當點擊時,打開使用指定的URL創建新選項卡。 我試圖鏈接到新選項卡中的網址的圖像是「images/ad1.jpg」,它在代碼中。請告訴我正確的代碼和它需要輸入的方式,以便我可以做到這一點。我非常感謝大家支持這個和stackoverflow的偉大社區。謝謝。使用jquery在點擊時有圖像鏈接到新標籤中的URL

(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); 
+0

僅供參考:您在函數調用中將'$'定義爲'jQuery',然後在您的代碼中將其引用爲'jQuery'。雖然這確實起作用,但它有點違背了以'$'傳遞它的目的。 – 2014-08-28 15:27:20

+0

下面的解決方案是否適合您?任何反饋? – 2014-08-30 16:01:18

回答

0

您應修改jquery.prettyPhoto.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")); 
}) 

我希望它會工作。

0

此庫有一個選項image_markup,documentation,使用這將避免javascript解決方案。

添加一個鏈接與target="_blank"image_markup選項中,當你實例prettyPhoto

image_markup: '<a href="{path}" target="_blank"><img id="fullResImage" src="{path}" /></a>' 

$("a[rel^='prettyPhoto']").prettyPhoto({image_markup: '<a href="{path}" target="_blank"><img id="fullResImage" src="{path}" /></a>'}); 

否則,你必須做這樣的事情,jsFiddle Example

$(document.body).on('click', '#fullResImage', function(){ 
    window.open(this.src, '_blank'); 
}); 
相關問題