2

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>
3
  • possible duplicate of How can i add javascript inside blogger? Commented Jan 17, 2015 at 12:09
  • Read the question properly before you answer it. Commented Jan 17, 2015 at 12:18
  • Plz remove the topmost comment about duplicacy of the post. Commented Jan 17, 2015 at 12:21

1 Answer 1

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.com/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.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.

Hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

You are an angel! Love you boss!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.