[英]How can I have a script in Blogspot template that uses the Blogspot variables?
我将以下Facebook iframe作为模板的一部分:
<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
,并且看不到来自在岛外。
显而易见的解决方法是使每个人都喜欢.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转义,但是我无法将变量data:post.url
替换为正确的值-字面意义仍然保持不变。
Grzenio。
这不会直接回答您的问题,但您可以使用
用data:post.url
替换data:post.canonicalUrl
这意味着您所有喜欢的人都将使用博客的.com版本。
因此,您无需使用任何javascript等。
要显示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
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.