Forum Moderators: open

Message Too Old, No Replies

Javascript error

         

sweetjs

10:18 am on Sep 2, 2005 (gmt 0)

10+ Year Member



Hi..
I tried to get the indexOf a string in a url..the code is below

1. alert(window.location.href.indexOf("first"));
2. if (window.location.href.indexOf("first")!= -1)
3. {
4. window1=window.open('','name','height=400,width=650');
5. ...
6. }
7. window1.close();
8. alert(window.location.href.indexOf("first"));
9. if (window.location.href.indexOf("second")!= -1)
10. {
11.alert(window1.document.getElementById("nametxt").length);
12. }

the statement
window.location.href.indexOf
works in 1,2 line
but shows an error in 8th line as

variable uses an Automation type not supported in Js

I dont know y it occurs..
plz give me solution..

Thanks in advance,
SweetJS

Bernard Marx

11:07 am on Sep 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



window1.document.getElementById("nametxt").length

1) The window ref held in

window1
doesn't look like it has been closed at this stage (even if it was opened at all)

2) Does the element with id, "nametext", have a

length
property?

sweetjs

11:17 am on Sep 2, 2005 (gmt 0)

10+ Year Member



yes that nametxt(name given radio buttons in window1) has length property..

i have closed that window1..
if i did wrong ..how to close that window window1 and come back ..?

sweetjs

11:21 am on Sep 2, 2005 (gmt 0)

10+ Year Member



Also, i tried the same by just adding the lines 8a and 8b..

1. alert(window.location.href.indexOf("first"));
2. if (window.location.href.indexOf("first")!= -1)
3. {
4. window1=window.open('','name','height=400,width=650');
5. ...
6. }
7. window1.close();
8. //alert(window.location.href.indexOf("first"));
8.a alert(window.location);
8.b alert(window.location.indexOf("first"));
9. if (window.location.href.indexOf("second")!= -1)
10. {
11.alert(window1.document.getElementById("nametxt").length);
12. }

output of the line 8a gives the complete url ..( if second window not closed can we get the url of the first window? )
so i tried 8b to get the index..but it shows the same error.

Bernard Marx

12:00 pm on Sep 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm still a little in the dark (having no markup to test this on), but I'll go ahead.

1) It still seems that window1 is opened on condition (ie not always), yet there is a statement that calls for it to be closed that will always be executed. Presumeably this statement will cause an error if window1 was not opened (ie condition evaluates false).

2) window.location.indexOf("first");

This is an error. locatio is an object, and has no indexOf method.
( OK, loaction can be assigned a url: location = "page.htm", but this is accommodated by an internal setter method )

Always use location.href to be sure of getteing a string

window.location.href.indexOf("first");