Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

position on javascript within the <body>


Reply

6 Posts   813 Views

Avatar
Futureweb

15 August 2011 at 5:23pm Community Member, 233 Posts

Hi,

I have a site which includes google adverts. To place the adverts on the page, you have to put javascript within the body, on the page where you want it.

However, silverstripe then dumps all the javascript stuff directly after this google adsense script. This is causing a problem with the facebook connect module in IE6 becuase it tries to reload the page while the containing element isn't loaded and closed off.

How would I put some javascript on the page, and keep the rest right at the end of document...

Avatar
Willr

15 August 2011 at 9:20pm Forum Moderator, 5511 Posts

If you put the script on the page using a plain <script ...> tag instead of the SS <% require %> then SS will not move you script.

Avatar
Futureweb

15 August 2011 at 9:55pm Community Member, 233 Posts

that's what I have:

the javascript is:

<script type="text/javascript"><!--
google_ad_client = "123123123123123";
google_ad_slot = "12312312313123";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

this is in my template. SS is then dumping all the other javacript files linked in using <% require javascript() %> just after my google adsense code. If I remove the google adsense the other javacscript stuff goes back to being at the bottom of the html....

Avatar
Futureweb

15 August 2011 at 10:00pm Community Member, 233 Posts

example here: http://www.munromap.co.uk/

Avatar
Willr

16 August 2011 at 8:36pm Forum Moderator, 5511 Posts

Yes this is how Requirements is designed to work.

Avatar
Futureweb

16 August 2011 at 10:11pm Community Member, 233 Posts

hmm, that seems a wee bit odd to me! So, if i want to have some script on the page - and also some right at the end of the html, I can't use <% require %> ??

The problem is actually with the facebookConnect module - this adds custom javascript which HAS to be at the very end of the html - otherwise it causes massive problems in IE6 - (eg, it just fails to load anything on the page and i get a white blank page and error message)

I've got it working just now by taking the javascript out of the facebook connect module, and writing it directly into the bottom of my main page.ss template file...