split() one document.frames not allowed

M

Muffinman

Hi,

I want to split the result from
window.frames['data_frame'].document.location;, this in order to find
out which page is currently opened in the specific frame. When I do it
like this:
var source = window.frames['data_frame'].document.location;
// var source = "W3Schools is great!";

index_source = source.split('/');


IE gives an error that this method or property is not supported by this
object. When I check it on the other var it is accepted. Is there any
way I can make this work? I already tried to do it with
document.getElementById().src etc.. but that is not very reliable.

Thanks in advance, Maarten
 
L

Lee

Muffinman said:
Hi,

I want to split the result from
window.frames['data_frame'].document.location;, this in order to find
out which page is currently opened in the specific frame. When I do it
like this:
var source = window.frames['data_frame'].document.location;
// var source = "W3Schools is great!";

index_source = source.split('/');


IE gives an error that this method or property is not supported by this
object.

The location attribute of a document is not a string (it's a Location object),
and so doesn't have a split() method. I believe the href attribute of Location
is a string, so:

window.frames['data_frame'].document.location.href.split('/');

should work.
 
R

RobB

Lee said:
Muffinman said:
Hi,

I want to split the result from
window.frames['data_frame'].document.location;, this in order to find
out which page is currently opened in the specific frame. When I do it
like this:
var source = window.frames['data_frame'].document.location;
// var source = "W3Schools is great!";

index_source = source.split('/');


IE gives an error that this method or property is not supported by this
object.

The location attribute of a document is not a string (it's a Location object),
and so doesn't have a split() method. I believe the href attribute of Location
is a string, so:

window.frames['data_frame'].document.location.href.split('/');

should work.

document.location has been deprecated for years, replaced by
document.URL (read-only by spec, read/write in - you guessed it). A
window's Location object is found at window.location, although it
appears that virtually all browsers now map document.location to
window.location, possibly to avoid errors. Because of the importance of
[window.]location it can be read directly as a string, or replaced with
a string. Of course, it isn't a string, and one thing you can't get
away with, as Lee noted, is to invoke String object methods on it.
Could do this:

function getURL(doc)
{
var m = null;
if (m = doc.URL.match(/[^\/\\]+$/))
return m[0];
return '';
}

alert(getURL(frames.data_frame.document));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top