How can I add JavaScript inside Blogger?
Asked Answered
M

6

30

I would like to add some JavaScript inside Blogger.

<script type="text/javascript">
window.open("http://www.page.html", "myWindow", 
    "status = 1, height = 400, width = 400, resizable = 0");
</script>

If I edit the HTML and I add " and ' they get converted to quote ...

If I add an HTML/JavaScript widget the code won't run.

Minta answered 23/6, 2011 at 5:30 Comment(1)
Add the script part to head tag of blogspot template Design > Template > Customize and Save the template. The blog post should now show the correct behaviour.Mariettamariette
C
20

Navigate to the Layout tab, click the "Add a Page Element" option and select the "HTML/Javascript" sub-option.

See the Layout Guide for more details.

Conjunctiva answered 23/6, 2011 at 12:57 Comment(0)
A
17

Create a post. Click to enter html as opposed to compose. Type your script. To the right Click Post Settings >> Options >> Compose Mode then change Show HTML Literally to Interpret HTML. It should now accept your script as a script intsead of text..

Astrodome answered 14/5, 2012 at 4:54 Comment(1)
Warning: I have found that this works fine, but you must never return to the Compose view or your JavaScript will disappear, always stay in HTML view for that post.Duwalt
F
16

Add your code like this:

<script type='text/javascript'>
//<![CDATA[

window.open("http://www.page.html", "myWindow", 
    "status = 1, height = 400, width = 400, resizable = 0");

//]]>
</script>
Falsehood answered 11/9, 2015 at 2:42 Comment(0)
C
5

You can run this code as an external source on your blog. How? Follow the below steps:

Step 1: Store your JavaScript code in github.com, pastebin.com or any file CDN.

Step 2: Use the below piece of code to call your JavaScript code from that external source:

<script src="http://example.com/script.js"/></script>

Include this code inside <head>.

Couteau answered 21/8, 2015 at 7:19 Comment(0)
D
4

Select Template. And click 'Edit HTML'. Now you can add your script.

enter image description here

Delano answered 2/9, 2015 at 14:49 Comment(0)
K
2

You should be able to add it to the page template. You can edit them from within the Blogger interface or download/edit/upload them.

Kimbell answered 23/6, 2011 at 12:48 Comment(1)
Add the script part to head tag of blogspot template Design > Template > Customize and Save the template. The blog post should now show the correct behaviour.Mariettamariette

© 2022 - 2024 — McMap. All rights reserved.