[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TYPO3-english] Javascript in HTML template



Hi,

did you check the created (html) code from TYPO3? Maybe there is something missing. Maybe post the code or sent it to me by mail.
Christian

On 03.12.2010 14:29, Cecilie Andersen wrote:
Hi,

Thanks for the reply. I just tested it just opening the html file
directly on the webserver, and this works. The script is called in the
bottom of the html template as it correctly don´t work if the script is
placed in the top of the html.

But any idea why typo3 influence this, as the fact it it works if I open
the html directly on the webserver

Regards
Cecilie.



""Christian Müller (Kitsunet)"" <[email protected]> skrev i
meddelelsen
news:[email protected]
Have you tried to open this html from the server (without TYPO3
involved)? I guess it won't work too, because actually you execute
your javascript right away, without checking if all of the page is
already loaded. Which can be fine on a local pc because there is no
loading time, but from the internet the html takes a bit to load and
your javascript is executed before the img tag with id="someimage"
exists in your browser and so you will get the error.

You should put that code into a function and execute that function
with window.onload [1].

Christian

[1] http://javascript.about.com/library/blonload.htm

On 01.12.2010 09:54, Cecilie Andersen wrote:
I have a problem regarding a Javascript in my html template.

When I run the template on my local pc it works, but when loading the
template on my typo3 site there is an error.

The javascript is the following (it just insert a random picture into a
<td>

<script type="text/javascript">
var aryimages = new Array('banner2.jpg');
document.getElementById("someimage").src =
aryimages[Math.floor(Math.random() * aryimages.length)];
</script>

</HEAD>

<body>

<div align="center">
<table border="0" style="border: 1px solid #319a63" width="956"
cellspacing="0" cellpadding="0" height="660">
<tr>
<td valign="bottom" width="956" height="153" id="menu" colspan="3"><img
id="someimage" src="">menu</td>
</tr>


When opening the page in typo3 I can see an explorer error, that calls
the following error:

'document.getElementById(...)' is null or not an object

- and it points to the line "document.getElementById("someimage").src =
aryimages[Math.floor(Math.random() * aryimages.length)];"

Anyone has knowledge about problem with inserting javascript ? as it
seems to be an typo3 related error, as it works fine on my local pc.

Regards
Cecilie

_______________________________________________
TYPO3-english mailing list
[email protected]
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english