PDA

View Full Version : Banners not showing up when JS in body tags


johnw
12-24-2003, 09:36 AM
I am trying to place a random banner on my message board's pages. I have tried using various javascript routines. One in particular that works just fine outside of the message board. In fact, it worked just fine on an old message board(I have just switched to a different board-a phpbb).

I believe it has something to do with placing <script language="javascript"></script> tags in the <body></body> tags. Anyone with any suggestions, much appreciated. I have noticed that the more js code that is in the <header> tags, the more of the code that is recognized.

Thanks.

Merry Christmas.

ucm
12-24-2003, 07:23 PM
if the script is trying to access an object that doesn't "exist" yet then the script will fail...

for example, the following won't work:

<body>
<script language="javascript">

document.getElementById('banner').src="http://blah.com/blah.gif";

</script>


<img src="" id="banner">
</body>


however, the following will work:

<body>


<img src="" id="banner">



<script language="javascript">

document.getElementById('banner').src="http://blah.com/blah.gif";

</script>


</body>



and also, another work around would be to do this:

<body onload="changeBannerToThis('http://blah.com/blah.gif');">

<script language="javascript">

function changeBannerToThis(theBannersNewSrc){

document.getElementById('banner').src=theBannersNewSrc;

}

</script>





<img src="" id="banner">


</body>



the reason behind this is that the browser will NEED to load in the html element that your script will mess with BEFORE the script tries to mess with it, otherwise either an error will pop up ( or if the error dialog is checked ot not display on errors then it wont error but a little caution triangle will still appear in thw status bar)



---- then again ----

it might be something with the php code you are using, please post the php and javascript banner code you are trying to get to work if my previous explaination was way off :D

johnw
12-24-2003, 07:44 PM
Thanks very much. Finally.