Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

How to Add a script on every subpages on the <head> tag and check if they are working

0 votes
481 views
asked Jun 21, 2012 in Q2A Core by markg

i tried to insert the code under the admin->Layout->Custom HTML in <HEAD> section of every page.

i have a condition that if the page is a subpage it will do this: document.getElementsByTagName('head').item(0).innerHTML+="<script type='text/javascript'>alert('Test');</scr"+"ipt>;

the code was inserted under the <head> tag but there was no alert. please help.

 

Thanks

1 Answer

+1 vote
answered Jun 22, 2012 by Scott

That is Javascript so you need to put it inside a <script> tag itself.

<script>
document.getElementsByTagName('head').item(0).innerHTML+="<script type='text/javascript'>alert('Test');</scr"+"ipt>;
</script>

However, the code you posted is just equivalent to this:

<script type='text/javascript'>alert('Test');</script>

So you can just put that instead.

...