load script after page load

Hi

I have this script to show a link rotator but it slows opening my page

<script type="text/javascript" src="http://rotator.tradetracker.nl/?r=5124&t=js"></script>

Is there a way to activate this script after my page has loaded

greetings
Jurgen
derksjAsked:
Who is Participating?
 
Kiran Paul VJComputer EngineerCommented:
i can see Sponsors in FF and IE7
some sponsors i see are
      Vliegtickets,
      Verre reizen naar Indonesië,
      vakantie Brazilie
0
 
Kiran Paul VJComputer EngineerCommented:
write <script type="text/javascript" src="http://rotator.tradetracker.nl/?r=5124&t=js"></script>

before

</body>
0
 
Kiran Paul VJComputer EngineerCommented:
this loads a javascript dynamicaly

var exScript = document.createElement('script');
exScript.src='http://www.somedomain.com/somescript.js';
var headTag = document.getElementsByTagName('head')[0];
headTag.appendChild(exScript);


check this also http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_22843854.html
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
discon0Commented:
It's better to keep the scripts inside the <head> of an html page.

You can change the line that loads the script from:
<script type="text/javascript" src="http://rotator.tradetracker.nl/?r=5124&t=js"></script>
to
<script type="text/javascript" id="my_script"></script>

and set the script's src tag after the page's load event.

Here's an example, tested in IE, Firefox and Opera.

<html>
<head>
      <script type="text/javascript" id="my_script" ></script>
      <script type="text/javascript">
      function my_init() {
                  // load the script
                  document.getElementById("my_script").src = "http://rotator.tradetracker.nl/?r=5124&t=js";
      }
      if (window.addEventListener) {
            window.addEventListener("load", my_init, false);
      } else if (window.attachEvent) {
            window.attachEvent("onload", my_init);
      }
      </script>
</head>
<body>
</body>
</html>

0
 
derksjAuthor Commented:
so i should write it like this?
I added your code in the script but its not working

<table width=95% border=0 cellspacing=0 cellpadding=3 class=list>   <tr align="left" class=column>
     <td COLSPAN=2>{column_forum}</td>
<td WIDTH="200">Sponsors</td>
     <td WIDTH="50" HEIGHT="20">{column_forum_threads}</td>
  <td WIDTH="50">{column_forum_posts}</td>
     <td WIDTH="100">{column_forum_last_post}</td>
    </tr>
<tr><td colspan=8 class=column><a href="index.{ext}?site={site}&cat={cat_id}">{cat_title}</a></td></tr>
<tr class=row>
 <TD width="50" VALIGN="MIDDLE" class=row>{state_icon}&nbsp;</TD>
 <TD height="20" valign=middle>
   <a href="index.{ext}?bn={bn_name}"><b>{bn_title}</b></a>
   <BR><span class=s_label>{descr}</span>
 </TD>
<TD width="200" valign="MIDDLE">

<script type="text/javascript" var exScript = document.createElement('script');
exScript.src='http://rotator.tradetracker.nl/?r=5124&t=js';
var headTag = document.getElementsByTagName('head')[0];
headTag.appendChild(exScript);></script>

</TD>
<td width="50" valign="middle"> {totalthreads}</td>
 <td width="50" valign="middle"> {totalnotes}</td>
 <td width="100" valign="middle" nowrap> {lastnote} {new_icon}</td></tr>
<tr class=light_row>
 <TD width="50" VALIGN="MIDDLE">{state_icon}&nbsp;</TD>
 <TD height="20" valign=middle>
   <a href="index.{ext}?bn={bn_name}"><b>{bn_title}</b></a>
   <BR><span class=s_label>{descr}</span>
 </TD>
<TD width="100" valign="MIDDLE"></TD>
 <td width="50" valign="middle"> {totalthreads}</td>
 <td width="50" valign="middle"> {totalnotes}</td>
 <td width="100" valign="middle" nowrap> {lastnote} {new_icon}</td></tr>
</table></td></tr><tr> <td align=right>{label_site_msg_stats}
0
 
Kiran Paul VJComputer EngineerCommented:
theres a typo in your code

try this

<script type="text/javascript">

var exScript = document.createElement('script');
exScript.src='http://rotator.tradetracker.nl/?r=5124&t=js';
var headTag = document.getElementsByTagName('head')[0];
headTag.appendChild(exScript);

</script>
0
 
Kiran Paul VJComputer EngineerCommented:
the fulll code will look like

<table width=95% border=0 cellspacing=0 cellpadding=3 class=list>   <tr align="left" class=column>
     <td COLSPAN=2>{column_forum}</td>
<td WIDTH="200">Sponsors</td>
     <td WIDTH="50" HEIGHT="20">{column_forum_threads}</td>
  <td WIDTH="50">{column_forum_posts}</td>
     <td WIDTH="100">{column_forum_last_post}</td>
    </tr>
<tr><td colspan=8 class=column><a href="index.{ext}?site={site}&cat={cat_id}">{cat_title}</a></td></tr>
<tr class=row>
 <TD width="50" VALIGN="MIDDLE" class=row>{state_icon}&nbsp;</TD>
 <TD height="20" valign=middle>
   <a href="index.{ext}?bn={bn_name}"><b>{bn_title}</b></a>
   <BR><span class=s_label>{descr}</span>
 </TD>
<TD width="200" valign="MIDDLE">


<script type="text/javascript">

var exScript = document.createElement('script');
exScript.src='http://rotator.tradetracker.nl/?r=5124&t=js';
var headTag = document.getElementsByTagName('head')[0];
headTag.appendChild(exScript);

</script>

</TD>
<td width="50" valign="middle"> {totalthreads}</td>
 <td width="50" valign="middle"> {totalnotes}</td>
 <td width="100" valign="middle" nowrap> {lastnote} {new_icon}</td></tr>
<tr class=light_row>
 <TD width="50" VALIGN="MIDDLE">{state_icon}&nbsp;</TD>
 <TD height="20" valign=middle>
   <a href="index.{ext}?bn={bn_name}"><b>{bn_title}</b></a>
   <BR><span class=s_label>{descr}</span>
 </TD>
<TD width="100" valign="MIDDLE"></TD>
 <td width="50" valign="middle"> {totalthreads}</td>
 <td width="50" valign="middle"> {totalnotes}</td>
 <td width="100" valign="middle" nowrap> {lastnote} {new_icon}</td></tr>
</table></td></tr><tr> <td align=right>{label_site_msg_stats}
0
 
Kiran Paul VJComputer EngineerCommented:
0
 
derksjAuthor Commented:
as you can see here

http://www.huahininthailand.com/index.php?site=huahinforumnl

i still get blank sponsors
0
 
derksjAuthor Commented:
many thanx

greetings
Jurgen
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.