2014-08-27 35 views
0
(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); 

我需要一些幫助。我正在嘗試在新選項卡中打開圖像(ad1.jpg)鏈接網址。我將如何做到這一點?我嘗試了很多方法來完成這項工作。我可能會把代碼放錯了,但我試過window.open,還有更多選項。任何幫助是極大的讚賞。謝謝!jquery用張貼的代碼打開新的圖像鏈接

+0

在你的代碼中你想打開一個新標籤? – jvecsei 2014-08-27 20:24:45

+0

此代碼位於index.html文件的頁腳中。啓動域時,代碼會正確顯示消息,但在單擊新標籤中的URL時需要該圖像。 – takashima 2014-08-27 20:29:22

+0

你目前觀察到了什麼行爲(鏈接是否在同一個標​​籤中打開?它不能在任何地方打開?)?什麼是相關的HTML? – jtheletter 2014-08-27 20:38:36

回答

0

試試這個:

(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 
      ); 
      $("#fullResImage").click(function() { 
       window.open("url/goes/here"); 
      }); 
      setTimeout(function() { 
       $.prettyPhoto.close(); 
      }, 10000); // autoclose after 10 seconds 
     } else { 
      console.log("PrettyPhoto is not defined."); // log this message 
     } 
    }); 
})(jQuery); 

這假設所顯示的圖像的圖像ID始終fullResImage。我在http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/documentation找到了相關信息。

+0

如果你看看腳本的圖片加載正常,我需要當你點擊圖片時它會在一個新標籤中打開一個URL – takashima 2014-08-27 20:41:21

+0

因此,像'var img = document.getElementById(「#theImage」); img.onclick = function(){window.open(「the/url/here」); ''? – TW80000 2014-08-27 20:43:39

+0

「$ .prettyPhoto.open」( 「images/ad1.jpg」,//要打開的圖像 「title」,//彈出標題 「desc。」//描述「起作用完美,需要images/ad1.jpg來點擊加載一個URL在另一個選項卡中 – takashima 2014-08-27 20:44:33