View Full Version : Preloading
PeterJS
12-24-2002, 09:17 PM
Is it possible to preload a javascript?
I have a page with some javascript on, but the page loads then the javascript loads. Its a script to remove some links from the page, but the user can get a quick glimpse of them before the script removes them.
or is there another script to prevent links from showing on the page before the user sees the page. So it would look like nothing has happened?
Thanks
Peter :)
Graeme Hackston
12-24-2002, 09:33 PM
Are you calling the js onload? Can we see an example of the js?
ez4me2c3d
12-24-2002, 09:50 PM
with the excpetion of functions all JS is loaded as it's read from the web file. for example.
<html>
<head>
<title>test</title>
<script>
window.status='the page is loading';
function hasLoaded () {
window.status+=' - well now it finished';
}
</script>
</head>
<body onLoad="hasLoaded()">
<script>
document.write("this line has been written to the page");
function noYet() {
document.write("but this line has not been written to the page");
}
</script>
</body>
</html>
So, to make JS do somthing before the page fully loads, don't put the code in a function then call it later, stick the exact code in the header section of your page between the <script> tags
Graeme Hackston
12-24-2002, 09:59 PM
ez4me2c3d that works for some things but probably won't work for PeterJS because he's removing page elements. You can't remove elements in open script (from the head) that don't exist yet. That's why I asked to see the js.
ez4me2c3d
12-24-2002, 11:07 PM
oo good point. very true.
PeterJS
12-25-2002, 03:41 AM
hi,
here's the script.....
<script type="text/javascript" language="javascript">
<!--
for(var i=0 ; i<document.links.length ; i++) {
if(document.links[i].innerText=="My Control Center") {
document.links[i].innerHTML='';}
if(document.links[i].innerText=="Login") {
document.links[i].innerHTML='';}
if(document.links[i].innerText=="Register Your Free Account (Required)") {
document.links[i].innerHTML='';}
if(document.links[i].innerText=="Logout") {
document.links[i].innerHTML='';}
if(document.links[i].innerText=="Show new only") {
document.links[i].innerHTML='';}
if(document.links[i].innerText=="Show all topics") {
document.links[i].innerHTML='';}
if(document.links[i].innerText=="Mark ALL forums read ") {
document.links[i].innerHTML='';}
if(document.links[i].innerText=="Mark forum read") {
document.links[i].innerHTML='';}
if(document.links[i].innerText=="Search") {
document.links[i].innerHTML='';}
if(document.links[i].innerText=="Help") {
document.links[i].innerHTML='';}
}
//-->
</script>
It was going to be used to replace the links with images, but I decided to remove the links and put my own menu made with gifs.
Problem is, the user will get a little glimpse of the old menu before they are removed.
thanks
Peter :)
ez4me2c3d
12-25-2002, 06:04 AM
looks like you could do something of the following instead of writting all links frist then removing the uneeded ones later...
<html>
<head>
</head>
<body>
<script>
(TRUE/FALSE) ? document.write('<a href="link_if_true">its true</a>') : document.write('<a href="link_if_false">its false</a>');
</script>
</body>
</html>
this way you only display the links you want based on a given condition for each link.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.