-->

我怎样才能在Blogspot的模板脚本,使用Blogspot的变量?(How can I have

2019-10-16 19:59发布

我有以下的Facebook iframe的作为模板的一部分:

<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取代为正确的值-它保持它字面上。

Answer 1:

为了显示你需要使用Blogger变量<data:blog.varName/>

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

var thisUrl = "data:post.url";

您需要使用:

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


UPD 1:如果你想使用网页网址头部分,使用<data:blog.url/>不是<data:post.url/>

UPD 2:但是你为什么不使用window.location



Answer 2:

Grzenio。

这并不直接回答你的问题,但你可以使用

替换data:post.urldata:post.canonicalUrl

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

所以,你不应该需要使用任何JavaScript等。



文章来源: How can I have a script in Blogspot template that uses the Blogspot variables?