2012-06-12 19 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等

相关问题