2010-04-06 67 views
0

我已經設置了pdf鏈接。我只是希望在我當前使用jQuery的href前加上Google的語法。我知道以下方法行不通,但我覺得我很接近......?使用jQuery與Google Docs打開PDF鏈接

 
jQuery(document).ready(function() { 
jQuery("a[href$=.pdf]").attr("href", "http://docs.google.com/viewer?url=" + current.href); 
}); 

反正可以幫忙嗎?

+1

難道你不是指'this.href'而不是'current.href'? – 2010-04-06 03:56:07

回答

2

只要你在原始文件中有絕對的網址,下面的內容應該可以工作。

$(document).ready(function() { 
    $("a[href$='.pdf']").each(function(){ 
     $(this).attr('href', 'http://docs.google.com/viewer?url=' + $(this).attr('href')); 
    }); 
});​ 
+0

謝謝admsteck!這正是我希望能夠實現的。 – Scott 2010-04-08 21:04:20

+0

進一步測試後,此方法似乎不適用於webkit瀏覽器 - safari和chrome。想法? – Scott 2010-04-11 18:46:52

+0

在[jsfiddle](http://jsfiddle.net/kHj2y/1/)上使用jquery 1.3.2和1.4.2和Google Chrome 4.0進行測試 – AdmSteck 2010-04-13 16:21:54