问题描述
我将以下Facebook iframe作为模板的一部分:
I have the following Facebook iframe as part of the template:
<iframe allowTransparency='true' expr:src='"http://www.facebook.com/plugins/like.php?href=" + data:post.url + "&layout=standard&show_faces=false&width=100&action=like&font=arial&colorscheme=light"' 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
,并且在岛外看不到任何喜欢的人.
The main feature is that it uses the Blogspot variable data:post.url
as the link that the user can "Like". Unfortunately recently blogspot decided to redirect people to their local blospot addresses, so if you open example.blogspot.com
in the UK, you will be redirected to example.blogspot.co.uk
, and you can't see any likes of people from outside of the island.
明显的解决方法是使每个人都喜欢.com主页,因此我创建了一个脚本来动态生成此iframe:
The obvious fix is to make everyone like the main .com page, so I created a script to generate this iframe dynamically:
<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转义,但我无法将变量data:post.url
替换为正确的值-实际上,它保持不变.
To make Blogspot accept it I had to html-ecape bits of it, but I can't get the variable data:post.url
substituted to a correct value - it stays literally what it is.
推荐答案
要显示Blogger变量,您需要使用<data:blog.varName/>
.
To show Blogger variables you need to use <data:blog.varName/>
.
因此,根据您的情况,而不是:
So, in your case, instead of:
var thisUrl = "data:post.url";
您需要使用:
var thisUrl = "<data:post.url/>";
UPD 1:如果要在标题部分使用页面网址,请使用<data:blog.url/>
而不是<data:post.url/>
.
UPD 1: if you want to use page url in head section, use <data:blog.url/>
not <data:post.url/>
.
UPD 2:但是为什么不使用window.location
?
UPD 2: but why you don't use window.location
?
这篇关于如何在Blogspot模板中有一个使用Blogspot变量的脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!