Forum Moderators: open
I'm using a script I had inquired about a while ago: [webmasterworld.com...]
The script has gotten rather large and is affecting load time in my page.
I copied the script & saved it in my IDE as machoRand.js & uploaded to server.
Then I tried to call the script by embedding this in my webpage:
<script language="JavaScript" src="http://www.mydomain.com/machoRand.js"></script>
It does not work.
I do the same thing with a "display date" script & it work.
Can anyone advise me on why it isn't working?
Thank you
-Fess
[edited by: Fess at 8:17 pm (utc) on Jan. 6, 2007]
Can anyone advise me on why it isn't working?
Fess load up FireFox, go to Tools->Javascript Console, and click the Clear button. Now go to the page. When you re-open the Javascript console at this point, it will give you some pretty specific errors.
If it says something like "object expected" then the .js is not loading for some reason.
I've been researching gov. funding for school and had little time to check this thread. Thanks for responding.
I took the code below, saved it as machoRand.js
I tried using the "full path" and "relative to root" but it does not work.
In FireFox, via the javaScript Console I got this error:
Error: syntax error
Source File: machoRand.js
Line: 1
Source Code:
<script> I no expert on javascript, but I cannot see this error, line 1 looks fine to me.....
-------------------------------------------------------
<script>
var totallinks=2
var image=new Array(totallinks)
var urls=new Array(totallinks)
var descriptions=new Array(totallinks)
var titles=new Array(totallinks)
image[0]="http://example.com/v2.0-img/pictures/autodesk/Maya85LRG.jpg"
urls[0]="http://example.com17C?18&CUR=840&DSP=&PGRP=0&ABCODE=&CACHE_ID=115874"
descriptions[0]="Autodesk Maya 8.5! Learn the GOD power!"
titles[0]="<b>Autodesk Maya 8.5</b>"
image[1]="http://example.com/v2.0-img/pictures/autodesk/CAD07RBTE.jpg"
urls[1]="http://example.com17C?&DSP=&PGRP=0&ABCODE=&CACHE_ID=1158740000115875"
descriptions[1]="Autodesk CAD! Enter the magic!"
titles[1]="<b>Autodesk CAD</b>"
image[1]="http://example.com/v2.0-img/pictures/autodesk/CAD07RBTE.jpg"
urls[1]="http://example.com17C?CUR=840&DSP=&PGRP=0&ABCODE=&CACHE_ID=115874"
descriptions[1]="Autodesk 3Dmax 9! The Powers of Gods!"
titles[1]="<b>Autodesk 3Dmax 9</b>"
var MachoManRandomSavage=Math.floor(Math.random()*totallinks)
</script>
<script>
var cont=titles[MachoManRandomSavage]+"<br>"+descriptions[MachoManRandomSavage]
cont+="<br><a href='"+urls[MachoManRandomSavage]+"' target='_blank'>"
cont+="<img src='"+image[MachoManRandomSavage]+"'><br>"
cont+="<br><a href='"+urls[MachoManRandomSavage]+"' target='_blank'><b>Preview This Package</b></a><br>"
document.write(cont)
</script>
[edited by: Brett_Tabke at 1:56 pm (utc) on Jan. 24, 2007]
[edit reason] shortened urls [/edit]
There is 1 script has me a little confused. It works but I just don't understand HOW its able to work.
This goes in between the <head> </head> tags:
<script language="JavaScript">function GetRandom(start,end)
{
var range = end - start + 1;
var result = start + Math.floor(Math.random()*range);
return result;
}
function getRandomLink(whichSet) {
contentlinks = new Array("http://forums.example.org/showthread.php?f=154&t=449125",
"http://forums.example.org/showthread.php?f=154&t=451100",
"http://forums.example.org/showthread.php?f=154&t=449581",
"http://forums.example.org/showthread.php?f=154&t=450662",
"http://forums.example.org/showthread.php?f=154&t=449114");
trafficlinks = new Array("http://www.example1.com",
"http://www.example2.com/zbrush/home/home.php",
"http://www.example3.com/",
"http://www.example4.com/",
"http://www.example5.com/",
"http://www.example6.com/");
if (whichSet==0) { window.open(contentlinks[GetRandom(0,contentlinks.length-1)]) }
else if (whichSet==1) { window.open(trafficlinks[GetRandom(0,trafficlinks.length-1)]) }
}
</script>
--------------------------------------------------------------
This goes in between the <body> </body> tags:
<A href="#" onclick="getRandomLink(1);return false;"><font face="Arial"><u>resources</u></font></A>
<A href="#" onclick="getRandomLink(0);return false;"><font face="Arial"><u>amimations</u></font></A>
--------------------------------------------------------------
Now, if I take the portion of the script that is in between the <head> tags & save it as something.js, call it by putting this in in between the head tags (<script type="text/javascript" src="http://www.mydomain.com/something.js"></script>)
How the heck can the body code work? Is it because, clicking the links in the body tells the script to check in the <head> tags?
just curious.....:)
Thanks
Fess
[edited by: jatar_k at 8:15 pm (utc) on Jan. 23, 2007]
Whether or not or not the script is included in the HTML document or called from an external file is largely irrelevant to the browser, it will execute the code in exactly the same way. The functions described by it will be globally available, so they can be called from the body of the document.
Andrew