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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

position on javascript within the <body>


Go to End


6 Posts   1202 Views

Avatar
JonShutt

Community Member, 244 Posts

15 August 2011 at 5:23pm

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

Forum Moderator, 5523 Posts

15 August 2011 at 9:20pm

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
JonShutt

Community Member, 244 Posts

15 August 2011 at 9:55pm

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
JonShutt

Community Member, 244 Posts

15 August 2011 at 10:00pm

Avatar
Willr

Forum Moderator, 5523 Posts

16 August 2011 at 8:36pm

Yes this is how Requirements is designed to work.

Avatar
JonShutt

Community Member, 244 Posts

16 August 2011 at 10:11pm

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