2012-06-12 20 views
1

我有以下的Facebook iframe的作爲模板的一部分:如何在使用Blogspot變量的Blogspot模板中有腳本?

<iframe allowTransparency='true' expr:src='&quot;http://www.facebook.com/plugins/like.php?href=&quot; + data:post.url + &quot;&amp;layout=standard&amp;show_faces=false&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&quot;' frameborder='0' scrolling='no' style='border:none; overflow:hidden; width:576px; height:24px;'/> 

的主要特點是,它採用的Blogspot變量data:post.url的鏈接,用戶可以「贊」。不幸的是,最近blogspot決定將用戶重定向到當地blospot地址,所以如果您在英國打開example.blogspot.com,您將被重定向到example.blogspot.co.uk,並且您看不到任何來自島外的人的喜好。

最明顯的解決方法是讓每個人都像主.COM頁面,所以我創建了一個腳本生成動態此iframe:

<script type="text/javascript"> 
document.write("<iframe allowTransparency='true' frameborder='0' scrolling='no' src='http://www.facebook.com/plugins/like.php?href="); 
var thisUrl = "data:post.url"; 
var beginning = thisUrl.indexOf("blogspot")+9; 
var end = thisUrl.indexOf("/", 15); 
document.write(thisUrl.substring(0, beginning)); 
document.write("com");//change regional url to com 
document.write(thisUrl.substring(end)); 
document.write("&layout=standard&show_faces=false&width=100&action=like&font=arial&colorscheme=light' style='border:none; overflow:hidden; width:576px; height:24px;'></iframe>"); 
</script> 

爲了Blogspot的接受它,我不得不HTML的ecape它位,但我無法將變量data:post.url替換爲正確的值 - 它保持字面意思。

回答

2

要顯示你需要使用 Blogger的變量。

所以,你的情況,而不是:

var thisUrl = "data:post.url"; 

您需要使用:

var thisUrl = "<data:post.url/>"; 


UPD 1:如果你想使用頁面URL中頭部分,使用<data:blog.url/>而不是<data:post.url/>

UPD 2:但爲什麼你不使用window.location

+0

回覆2:因爲我希望它也可以用於主博客頁面(列出一些最新的博客條目)。 – Grzenio

3

Grzenio。

這並不直接回答你的問題,但你可以使用

更換data:post.urldata:post.canonicalUrl

這將意味着你所有的喜好等將使用您的博客.com版本。

所以,你不應該需要使用任何JavaScript等

相關問題