Mansour Alfayez
Mansour Alfayez

Reputation: 11

Loading a JS code after a page loads

I have an advertisement JS code installed on my forum, and I want it to be loaded after the forum has been fully loaded, How to do that?

This is the JS code:

<script type="text/javascript" language="javascript" src="http://adv.sitemarketing.sa/components/com_adagency/ad_agency_zone.php?zid=261"></script>

I have five of them.

Upvotes: 0

Views: 39

Answers (2)

Pupil
Pupil

Reputation: 23978

Just add the JS at the bottom close to </body>.

<script type="text/javascript" language="javascript" src="http://adv.sitemarketing.sa/components/com_adagency/ad_agency_zone.php?zid=261"></script>

This is the way Bootstrap loads js.

Upvotes: 1

euvl
euvl

Reputation: 4776

You can try to add script after page is loaded:

<script type="text/javascript">
function downloadJS() {
  var element = document.createElement("script");
    element.src = "http://adv.sitemarketing.sa/components/com_adagency/ad_agency_zone.php?zid=261";
  document.body.appendChild(element);
}
if (window.addEventListener) {
  window.addEventListener("load", downloadJS, false);
} else if (window.attachEvent) {
  window.attachEvent("onload", downloadJS);
} else window.onload = downloadJS;
</script>

Upvotes: 1

Related Questions