最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to add Javascript into Blogger pages? - Stack Overflow

programmeradmin2浏览0评论

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("","_self")
}
</script>
</div>
</div>

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./tinny-tots-baby-bottle-cover/p/itme3h9rvenhxvxb?pid=BTCE3H9RGFD3Z7JR","_self")
}
</script>
</div>
</div>
Share Improve this question asked Jan 17, 2015 at 12:06 androidrillandroidrill 993 silver badges11 bronze badges 3
  • possible duplicate of How can i add javascript inside blogger? – vjdhama Commented Jan 17, 2015 at 12:09
  • Read the question properly before you answer it. – androidrill Commented Jan 17, 2015 at 12:18
  • Plz remove the topmost ment about duplicacy of the post. – androidrill Commented Jan 17, 2015 at 12:21
Add a ment  | 

1 Answer 1

Reset to default 6

I had the same problem recently.

You need to wrap your script like so

<script type='text/javascript'>
//<![CDATA[
function myFunction() {
var btn = document.createElement("BUTTON");
window.open("http://www.amazon./tinny-tots-baby-bottle-cover/p/itme3h9rvenhxvxb?pid=BTCE3H9RGFD3Z7JR","_self")
}
//]]>
</script>

The term CDATA tells the XML parser not to parse the wrapped text data. For more info on CDATA, check this answer.

Also I followed this advise:

Adding Scripts in Blogger is extremely straightforward. All you need to do is to go to Blogger. >> 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.

Hope it helps.

发布评论

评论列表(0)

  1. 暂无评论