Martin Holland
Martin Holland

Reputation: 291

How can you add in Javascript resources at the very bottom of an xpage?

I need to include a javascript file right at the end of the xpage so it gets loaded after the XSP.addOnLoad event code which is generated automatically e.g.

XSP.addOnLoad(function() {
XSP.attachEvent....
}
<script src="my.js">

Ideally I want to include it as part of a theme but if I do that it goes into the HEAD section

So can I either.. -Specify in a theme to insert the link to a client side js resource at the bottom of the page rather than the head -Include a resource on an xpage directly so it goes after the auto-generated code

NB: This it needed in order to get an xpages app working with Foundations http://foundation.zurb.com/docs/

I need to include the foundations js file after the events have been bound to the fields

Thanks!

Upvotes: 0

Views: 1140

Answers (1)

Panu Haaramo
Panu Haaramo

Reputation: 2932

Try adding a script block in the end with this code:

XSP.addOnLoad(function() {
  document.write('<script src="my.js">');
}

However this may execute before the generated XSP.addOnLoad. You could then try a small hack like this:

XSP.addOnLoad(function() {
  setTimeout(document.write('<script src="my.js">'), 200);
}

Upvotes: 1

Related Questions