2017-08-14 44 views
1

在blogspot模板引擎中,如何转义后期URL以将其用作查询参数,以便您可以在Facebook/Twitter /任何按钮和iframe中使用它?博客 - 如何百分比编码一个URL /转义它作为查询参数?

问题:我有一个带有一个带有URL的src的iframe。

<iframe src="https://www.facebook.com/plugins/like.php?href=MY_URL_GOES_HERE"> 

所以说我的帖子的URL是http://example.blogspot.com/1999/01/first.html。我需要:/.转换为百分比编码的字符,也?&%等,否则我得到这样的:

<iframe src="https://www.facebook.com/plugins/like.php?href=http://example.blogspot.com/1999/01/first.html"> 

这只是看起来像它会打破一天。我如何在博客中转义该网址?

回答

3

做这件事的方法很简单,只需要花费几个小时搜索互联网的每个角落,以获取blogspot模板引擎上的一些文档外观,并通过一堆StackOverflow的答案来阅读,只是解除了问题与“使用shareurl代替”。

无论如何。 blogspot模板中的每个字符串都有一个.escaped字段,即字符串转义字符。这就对了。你只是anyurl.escaped,它的作品。它可以是data:post.url.escapeddata:post.url.canonical.escaped或其他。

<iframe 
    expr:src="&quot;https://www.facebook.com/plugins/like.php?href=&quot; 
    + data:post.url.canonical.escaped + &quot;width=173&amp;layout=button_count&amp;action=like&amp;size=small&amp;show_faces=false&amp;share=true&amp;height=46&amp;appId=YOUR_APP_ID_HERE&quot;" width="173" 
height="46" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe> 

其他难以捉摸的字符串属性可以在这个极其腥博客上找到:http://template-data.blogspot.com.br/2016/04/title_58.html

你会认为谷歌将有此信息的地方容易找到,但他们所得到的都是博主HTTP API文档?什么?