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
1 Answer
Reset to default 6I 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.