Click to See Complete Forum and Search --> : This code has some error!


aoeguy
10-19-2003, 08:29 AM
Whats the fault here?!?

<script>

function E404(){
var pageURL=location.href //THIS PAGE
var nfp="http://home.tiscalinet.ch/banditsclan/404.htm" //GoTo
//REDIRECT PAGE
var redir=nfp+"?404="+pageURL
//document.write(redir)
window.setTimeout("location.href=redir,1")
}

</script>

Answers please

Charles
10-19-2003, 08:37 AM
1) The SCRIPT element requires a "type" attribute.

2) You are misusing the "setTimeout()" method.

<script type="text/javascript">
<!--
function E404(){window.setTimeout("location.href = 'http://home.tiscalinet.ch/banditsclan/404.htm' + '?404=' + location.href", 1)}
// -->
</script>

aoeguy
10-19-2003, 08:47 AM
thanks

Whats the difference between the script and the type="text/javascript" ?

Charles
10-19-2003, 08:51 AM
Originally posted by aoeguy
Whats the difference between the script and the type="text/javascript" ? The one is right and the other is wrong. There are lots of client side scripting languages out there. See http://www.w3.org/TR/html4/interact/scripts.html#edef-SCRIPT.

fredmv
10-19-2003, 06:26 PM
Originally posted by aoeguy
Whats the difference between the script and the type="text/javascript" ? Under certain DOCTYPEs you need to define a type attribute in the <script> element. However, the <script> element defaults to JavaScript.

Charles
10-19-2003, 06:56 PM
Originally posted by fredmv
However, the <script> element defaults to JavaScript. From the HTML 4.01 Specification:
Documents that do not specify default scripting language information and that contain elements that specify an intrinsic event script are incorrect. User agents may still attempt to interpret incorrectly specified scripts but are not required to.
http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.2.1

fredmv
10-19-2003, 06:59 PM
Point well taken. I remember reading that somewhere and it seems to be correct. Thanks for clearing that up though. ;)

Although if you run the following code for example (note that the language or type attribute is not defined):<script>
alert("Hello, World");
</script>Under Mozilla Firebird 0.7 and IE6, it is executed as JavaScript.

Charles
10-19-2003, 07:04 PM
Yes, some browseres do quite well at recovering from HTML errors. But we ought to publish correct mark up nonetheless.

fredmv
10-19-2003, 07:09 PM
I completely agree with you.