Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help: lastIndexOf is not a function

2,375 views
Skip to first unread message

Mario Dorion

unread,
Mar 4, 1996, 3:00:00 AM3/4/96
to
Why is this causing me a "lastIndexOf is not a function" error:

var URL = top.location;
var idx = URl.lastIndexOf("somestring");

This one works, though:

var URL = "somestring";
var idx = URl.lastIndexOf("somestring");

It seems it fails to notice that the first URL is really a string.
Is there a way I can cast it?

Thanks in advance as my neck is on the line!

--
Mario Dorion <Ma...@SCVN.Com>

Danny Goodman

unread,
Mar 4, 1996, 3:00:00 AM3/4/96
to
Mario Dorion wrote:
>
> Why is this causing me a "lastIndexOf is not a function" error:
>
> var URL = top.location;
> var idx = URl.lastIndexOf("somestring");
>
> This one works, though:
>
> var URL = "somestring";
> var idx = URl.lastIndexOf("somestring");
>

Variable names are case-sensitive. You change the case of the "L" from
URL to URl, which will throw off the lastIndexOf() method.

Danny
http://www.dannyg.com

Gordon McComb

unread,
Mar 7, 1996, 3:00:00 AM3/7/96
to
Still won't work. URL is a reference to an object, and can't be used directly with
string methods. It has to be:

var URL = top.location.href;

or

var URL = top.location.toString();

-- Gordon

PS: How was the Java/JavaScript conference?

robwil...@gmail.com

unread,
Jul 8, 2019, 5:19:07 AM7/8/19
to
On Monday, 4 March 1996 08:00:00 UTC, Mario Dorion wrote:
> Why is this causing me a "lastIndexOf is not a function" error:
>
> var URL = top.location;
> var idx = URl.lastIndexOf("somestring");
>
> This one works, though:
>
> var URL = "somestring";
> var idx = URl.lastIndexOf("somestring");
>
> It seems it fails to notice that the first URL is really a string.
> Is there a way I can cast it?
>
> Thanks in advance as my neck is on the line!
>
> --
> Mario Dorion <Ma...@SCVN.Com>

top.location is an object, perhaps you mean top.location.href

dr.j.r....@gmail.com

unread,
Jul 8, 2019, 7:39:20 AM7/8/19
to
Perhaps you should go back to 1996, at which time your reply might have been more useful.

PKUATBT.
0 new messages