BakaBT > Need Help? Ask Here

Javascript overwriting window.onload() event

(1/2) > >>

Malific:
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: ---
<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>
--- End code ---

And this in the body for the banner itself:

--- Code: ---
<SCRIPT LANGUAGE="JavaScript">
  adNo = Math.round(Math.random() * maxAdNo)
  document.write(myAd[adNo])
</SCRIPT>
--- End code ---

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?

Xiong Chiamiov:
Don't capitalize your html tags.

You should be able to just add a call to bxt_resize_iframe() after the document.write().

Malific:
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.

Xiong Chiamiov:

--- Quote from: Malific 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>

--- End quote ---
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.

--- End quote ---
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?

Jarudin:

--- Code: 'girls bravo' ---
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", ""]

--- End code ---

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--

Navigation

[0] Message Index

[#] Next page

Go to full version