如何将 Javascript 添加到 Blogger 页面?
How to add Javascript into Blogger pages?
I have made a blog using blogger and now I want to customize it. All I want is to be able to add a button having Javascipt's onclick() in blogger's page behind HTML. I tried all the tricks but it is somehow not working.
<div>
<div>
<img src="C:\Users\dell\Desktop\goldfavicon.jpg" height="98px" width="98px"/>
</div>
<div>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var btn = document.createElement("BUTTON");
window.open("http://www.amazon.com/tinny-tots-baby-bottle-cover/p/itme3h9rvenhxvxb?pid=BTCE3H9RGFD3Z7JR","_self")
}
</script>
</div>
</div>
我最近遇到了同样的问题。
你需要像这样包装你的脚本
<script type='text/javascript'>
//<![CDATA[
function myFunction() {
var btn = document.createElement("BUTTON");
window.open("http://www.amazon.com/tinny-tots-baby-bottle-cover/p/itme3h9rvenhxvxb?pid=BTCE3H9RGFD3Z7JR","_self")
}
//]]>
</script>
术语 CDATA 告诉 XML 解析器不要解析包装的文本数据。有关 CDATA 的更多信息,请查看 this answer.
我也关注了this advise:
Adding Scripts in Blogger is extremely straightforward. All you need
to do is to go to Blogger.com >> Your site >> Template >> Edit HTML.
Now it depends on you where you would like to paste your JavaScript
coding. However, we prefer you to add it above the tag because
this is the place where all technical things are present.
希望对您有所帮助。
I have made a blog using blogger and now I want to customize it. All I want is to be able to add a button having Javascipt's onclick() in blogger's page behind HTML. I tried all the tricks but it is somehow not working.
<div>
<div>
<img src="C:\Users\dell\Desktop\goldfavicon.jpg" height="98px" width="98px"/>
</div>
<div>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var btn = document.createElement("BUTTON");
window.open("http://www.amazon.com/tinny-tots-baby-bottle-cover/p/itme3h9rvenhxvxb?pid=BTCE3H9RGFD3Z7JR","_self")
}
</script>
</div>
</div>
我最近遇到了同样的问题。
你需要像这样包装你的脚本
<script type='text/javascript'>
//<![CDATA[
function myFunction() {
var btn = document.createElement("BUTTON");
window.open("http://www.amazon.com/tinny-tots-baby-bottle-cover/p/itme3h9rvenhxvxb?pid=BTCE3H9RGFD3Z7JR","_self")
}
//]]>
</script>
术语 CDATA 告诉 XML 解析器不要解析包装的文本数据。有关 CDATA 的更多信息,请查看 this answer.
我也关注了this advise:
Adding Scripts in Blogger is extremely straightforward. All you need to do is to go to Blogger.com >> Your site >> Template >> Edit HTML. Now it depends on you where you would like to paste your JavaScript coding. However, we prefer you to add it above the tag because this is the place where all technical things are present.
希望对您有所帮助。