Lee wrote:
Muffinman said:
Hi,
I want to split the result from
window.frames['data_frame'].document.location;, this in order to
findout which page is currently opened in the specific frame. When I do
itlike 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
thisobject.
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));