Click to See Complete Forum and Search --> : document.location.href doesn't work


kariba
02-06-2003, 08:45 PM
Hello everybody,

in my javascript I am trying to find out location of one of the iframe on my page.

var currentURL = document.iframe["iFrame"].location.href.ToString();

but this doesn't work.

Can anyone help me?

Thank you,

MIke

khalidali63
02-06-2003, 09:09 PM
Your code should work in IE at least,but I have a feeling that you are trying to access a URL out of your domain.

You can only access urls which reside on your webserver.

cheers

Khalid

kariba
02-14-2003, 05:50 PM
Hello,

I am sorry it took me so long to get back.

It is working now with this:

currentURL = top.iFrame.location.href;

But what I need to work with is the href without parameters.

So I need to get something like this:
http://forums.webdeveloper.com/newreply.php

instead of
http://forums.webdeveloper.com/newreply.php?action=newreply&threadid=3714[/url]

THank you for your help.

Mike

Charles
02-14-2003, 06:09 PM
Originally posted by kariba
var currentURL = document.iframe["iFrame"].location.href.ToString();Unless you made one of your own, there is no ToString() method. There is, however, a toString() method. But you don't need either. The property location.href is already a string. And location.toString() simply returns location.href.

kariba
02-14-2003, 06:12 PM
Hello,

I am sorry it took me so long to get back.

It is working now with this:

currentURL = top.iFrame.location.href;

But what I need to work with is the href without parameters.

So I need to get something like this:
http://forums.webdeveloper.com/newreply.php

instead of
http://forums.webdeveloper.com/newreply.php?action=newreply&threadid=3714[/url]

THank you for your help.

Mike

Charles
02-14-2003, 06:45 PM
currentURL = top.iFrame.location.href.replace(/\?+/,'');

kariba
02-14-2003, 07:03 PM
Hi,

unfortunatelly this doesn't work..
currentURL = top.iFrame.location.href.replace(/\?+/,'');

just removes the '?' but leaves the params.

Can't I do it somehow with indexes?

Thank you,

Mike

Charles
02-14-2003, 07:49 PM
Oops, sorry about that.

currentURL = top.iFrame.location.href.replace(/\?.*/,'');

kariba
02-14-2003, 08:32 PM
Thanks a lot Charles.

It works great.

Mike