Author Topic: Javascript overwriting window.onload() event  (Read 856 times)

Offline Malific

  • Member
  • Posts: 269
    • Malific's Script Shop
Javascript overwriting window.onload() event
« on: October 23, 2009, 05:13:18 PM »
I'm using the following coed to create a random picture banner for cccp. I've been using it since before the current Window resize function and only today noticed that my description windows are too large now.

I use html to do my descriptions with this in the head:
Code: [Select]
<SCRIPT LANGUAGE="JavaScript">
var maxAdNo = 4
var adNo
var myAd = new Array()
myAd[0] = '<IMG SRC="http://www.malific.com/pics/BxT/cccp/Hanyou_banner_answer.png">'
myAd[1] = '<IMG SRC="http://www.malific.com/pics/BxT/cccp/BTN_KAACCCP_Banner1.gif">'
myAd[2] = '<IMG SRC="http://www.malific.com/pics/BxT/cccp/Cccp_banner_12_by_check.png">'
myAd[3] = '<IMG SRC="http://www.malific.com/pics/BxT/cccp/Cccp_banner_14_by_check.png">'
myAd[4] = '<IMG SRC="http://www.malific.com/pics/BxT/cccp/Dogfoodbanner03.gif">'
</script>

And this in the body for the banner itself:
Code: [Select]
<SCRIPT LANGUAGE="JavaScript">
  adNo = Math.round(Math.random() * maxAdNo)
  document.write(myAd[adNo])
</SCRIPT>

I personally don't know javascript and got this snippet from a friend. Does anyone know how i can retain my random picture banner without messing with the resize function of BakaBT?

Offline Xiong Chiamiov

  • Member
  • Posts: 3012
  • I'm gonna tolerate and love the SHIT out of you!
    • changedmy.name
Re: Javascript overwriting window.onload() event
« Reply #1 on: October 23, 2009, 06:31:00 PM »
Don't capitalize your html tags.

You should be able to just add a call to bxt_resize_iframe() after the document.write().
Projects of interest: nagi | sheska | bdg
Posts made between 2009-05-09 and 2011-08-26 were in the capacity of staff.  Please read accordingly.

Offline Malific

  • Member
  • Posts: 269
    • Malific's Script Shop
Re: Javascript overwriting window.onload() event
« Reply #2 on: October 23, 2009, 07:50:53 PM »
AS I said I don't know Javascript at all so I'm assuming by add a call you mean to do this:


<SCRIPT LANGUAGE="JavaScript">
  adNo = Math.round(Math.random() * maxAdNo)
  document.write(myAd[adNo])
  bxt_resize_iframe()  <---- just put this line here?
</SCRIPT>

As to capitalizing my html tags, I've done that ever since I've been doing HTML (about 15 years) and it's never given me any issues. I do it mainly to help visually separate tags from content, just easier to find them in the code, but if there's an actual reason not to I'd like to know.

::edit::
I attempted to above edit and unfortunately it didn't work.
« Last Edit: October 23, 2009, 08:15:57 PM by Malific »

Offline Xiong Chiamiov

  • Member
  • Posts: 3012
  • I'm gonna tolerate and love the SHIT out of you!
    • changedmy.name
Re: Javascript overwriting window.onload() event
« Reply #3 on: October 23, 2009, 08:37:23 PM »
AS I said I don't know Javascript at all so I'm assuming by add a call you mean to do this:


<SCRIPT LANGUAGE="JavaScript">
  adNo = Math.round(Math.random() * maxAdNo)
  document.write(myAd[adNo])
  bxt_resize_iframe()  <---- just put this line here?
</SCRIPT>
Yep, although you should be ending your lines with semicolons.  It really shouldn't be working at all right now.

Quote
As to capitalizing my html tags, I've done that ever since I've been doing HTML (about 15 years) and it's never given me any issues. I do it mainly to help visually separate tags from content, just easier to find them in the code, but if there's an actual reason not to I'd like to know.
It's ugly and distracting, but more importantly, it's not xhtml-compatible.

Can you give some full example code here, so we can play around with it in the sandbox?
Projects of interest: nagi | sheska | bdg
Posts made between 2009-05-09 and 2011-08-26 were in the capacity of staff.  Please read accordingly.

Offline Jarudin

  • Member
  • Posts: 6875
Re: Javascript overwriting window.onload() event
« Reply #4 on: October 23, 2009, 10:30:02 PM »
Code: 'girls bravo' [Select]

var fadeimages=new Array()
//SET IMAGE PATHS. Extend or contract array as needed
fadeimages2[0]=["http://www.malific.com/pics/BxT/cccp/Hanyou_banner_answer.png", "http://www.cccp-project.net/wiki/index.php?title=Main_Page", ""]

fadeimages2 is undefined <-- breaks the Javascipt

After investigation I found out the other descriptions fail because of the </BODY> at the end.
There are two ways my resize script can detect the correct height of the page and because the body tag was capitalized that method failed and the entire script failed.
Edit: fixed.

Like Xiong Chiamiov said your code doesn't follow HTML standard, but neither do browsers and they render your description fine.
That doesn't make your code very nice to read though ^^

Oh, and you don't need to call the resize manually as you're not overwriting the onload event.

--Jarudin--
« Last Edit: October 23, 2009, 10:32:10 PM by Jarudin »
Baby, I love the way you move

Offline Malific

  • Member
  • Posts: 269
    • Malific's Script Shop
Re: Javascript overwriting window.onload() event
« Reply #5 on: October 24, 2009, 04:15:47 AM »
Okay I've gone through and changed the case of everything I can find.

As to semi colons, Again I now virtually nothing about javascript this is just code I was given.

Either way, Jarudin, That Girls Bravo Page was a separate set of code I was trying to get to work and was failing to have function properly. You found the issue I couldn't and it works now so thanks for that. That code will be replacing the code above on all my descriptions now. Again something I got from someone else and was trying to make it function for my purposes.

All in all everything is solved and all my descriptions are functioning properly now, Thanks for the help guys.