Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return a string with a frame's source

Status
Not open for further replies.

cthaxter

Programmer
Aug 2, 2001
71
US
I need to perform certain actions based on which page is loaded in frame "main". These actions (such as document.write) will be performed in frame "leftnavbar", where "leftnavbar.html" will always be loaded. "main" might have "aboutus.html" loaded in it, or "services.html", or any other number of pages.

I need to construct "leftnavbar.html" so that it changes based on which page is loaded in "main".

I think this means I need to handle the following variable

var mainlocation=parent.main.location

as a string, but it isn't a string. I can't return mainlocation.indexOf("services.html") for example. If I try alert(mainlocation) then I get the complete file path. I want to be able to extract the last portion of it. In VBScript I would have used a right(mainlocation, 13) or str(mainlocation) if mainlocation is a string, or mainlocation.value if it is an object that supports .value.

Any help?

Thanks.

-Christopher
 
Of course you can do this.
Actually, what you did is almost right. The "location" is not a string - it's an object, and you have to use one of it's properties to define some portion of the URL.

In general, any URL is can be described as this:

protocol//host:port/pathname#hash?search

("protocol" part may be of these:
[tt]javascript: | http: | ftp: | news:[/tt] and some others)

In javascript there are properties of standard location object:

hash - specifies an anchor name in the URL

host - specifies the host and domain name, or IP address, of a network host

hostname - specifies the host:port portion of the URL

href - specifies the entire URL

pathname - specifies the url-path portion of the URL

port - specifies the communications port that the server uses for communications

protocol - specifies the beginning of the URL, including the colon

search - specifies a query substring


Using these ones you can get any part of URL.

good luck


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top