Forum Moderators: open

Message Too Old, No Replies

window.location is addicted to setTimeout

Works when inside setTimeout, doesn't work by itself

         

MichaelBluejay

1:41 am on Nov 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here's a weird one. This works fine:

[center] setTimeout('window.location = theURL', '0');
[/center]

But this does not:

[center] window.location=theURL;
[/center]

Actually, it works fine in IE6/Win. But with NN4/Mac nothing happens (and no error is generated), and in Safari/Mac nothing happens either.

Thanks for your help, -MBJ-

korkus2000

3:16 am on Nov 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What happens if you use window.location.href=theURL;?

MichaelBluejay

3:49 am on Nov 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, this is weird, it suddenly started working, even without the .href. My computer is haunted.

So let me throw something else at you all. NN4 doesn't like this code:

description=document.myform.description.value;

It says, "document.myform has no properties." But IE thinks the code is just fabulous.

Here's the form code. I'm just using it to store some data, the form never gets submitted:

[1]<TABLE style="position:absolute; visibility:hide">
<TR>
<TD>
<FORM ACTION="" METHOD=POST name=myform style="visibility:hidden">
<INPUT TYPE=text NAME=description VALUE="my description here">
<INPUT TYPE=text NAME=amount VALUE="27.06">
<INPUT TYPE=text NAME=frequency VALUE="1" SIZE=2>
</FORM>
</TD></TR></TABLE>
[/1]

Any ideas? Thankie-doodle, -MBJ-

korkus2000

4:03 am on Nov 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What DTD are you using? Also quote all of your attributes in the form.

DrDoc

4:05 am on Nov 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want a script to work in NN4, you need to use document.layers. I recommend assigning an ID to the element.

<INPUT TYPE=text NAME=description id="description" VALUE="my description here">

Then, in your script, do something like this:

if(document.getElementById) {
//This will make your script work in DOM compliant browsers
description = document.getElementById('description').value;
}
else if(document.all) {
//This is for IE4-5
description = document.all['description'].value;
//This is where you could've done what you already do:
//description = document.myform.description.value;
}
else if(document.layers) {
//For the NN4 beast...
description = document.layers('description').value;
}

MichaelBluejay

4:37 am on Nov 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for your help, DrDoc. What a bummer that I have to add a bunch of code just to allow NN4 to get a value from a field! I think maybe I'll let NN4 users suffer instead. Although I guess anyone who's still using NN4 is suffering by default....

Korkus, I don't know what "DTD" is, and I don't know what you mean by that I should quote all attributes in the form, but if DrDoc's answer is the easiest solution for allowing NN4 to get a value from a field, then I guess it doesn't matter.

Thanks again, -MBJ-

DrDoc

4:44 am on Nov 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DTD = Document Type Definition. Declared in the DOCTYPE tag.

Quote all attributes = Instead of <input type=text> you should do <input type="text"> etc. Also, it's better to use all lowercase tags (and attributes).

MichaelBluejay

4:52 am on Nov 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't use document type definitions because my ancient version of Claris Home Page doesn't understand it, and it sticks it between <HEAD></HEAD> where I assume it doesn't do any good.

Is it going to be a problem that I don't use DTD's? What's the bad result that could happen?

Thanks, -MBJ-

DrDoc

5:23 am on Nov 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First of all -- IE will render your page in "quirks mode". What does that mean? Well, "quirks mode" is just another term for "bug mode". In other words, it will purposefully render your page in an incorrect way. Unfortunately, IE is always buggy -- so I guess it's just a matter of which of the two "buggy" modes is worse.

As far as other browsers goes... To help you understand the problem you need to undertand what exactly a DTD is. A document type definition serves as a heads up for the browser. It tells the browser which version of the HTML standard you have attempted to follow. This saves the browser some guessing. Compare it to different styles of writing. For example, if you're an archaeologist you are supposed to follow the SAA guide. For other types of writing you are supposed to following a different standard. This helps a reader (or editor) to follow your line of thinking better.

Likewise, specifying a DTD lets the browser know in advance what to expect, and render the page accordingly. When it comes to most non-IE browsers (such as Mozilla or Opera) they tend to render your page better when the DTD is present, provided that your page actually follows the DTD ;)