[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

load script after page load

Posted on 2007-10-18
10
Medium Priority
?
1,172 Views
Last Modified: 2010-09-22
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
0
Comment
Question by:derksj
  • 6
  • 3
10 Comments
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 20100149
write <script type="text/javascript" src="http://rotator.tradetracker.nl/?r=5124&t=js"></script>

before

</body>
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 20100166
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
 
LVL 5

Assisted Solution

by:discon0
discon0 earned 100 total points
ID: 20100289
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:derksj
ID: 20100322
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
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 20100426
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
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 20100435
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
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 20100445
0
 

Author Comment

by:derksj
ID: 20100697
as you can see here

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

i still get blank sponsors
0
 
LVL 16

Accepted Solution

by:
Kiran Paul VJ earned 400 total points
ID: 20100821
i can see Sponsors in FF and IE7
some sponsors i see are
      Vliegtickets,
      Verre reizen naar Indonesië,
      vakantie Brazilie
0
 

Author Comment

by:derksj
ID: 20100889
many thanx

greetings
Jurgen
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question