accessing frames and changing location.href

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

accessing frames and changing location.href

Post by raghavan20 »

I have a page index.php
It has two frames, userMenus and mainFrame.
I have another page called homepage.php which has link to admin page.
the admin page actually consists of adminMenus.php and adminPage.php which is loaded on userMenus and mainFrame frames in index.php respectively.
If I now click on the homepage.php, then adminMenus.php should load in userMenus.php in index.php
and adminPage.php should load in mainFrame.php in index.php
I dont know wot to fill in these gaps.


Code: Select all

onclick=\"(????).mainFrame.location.href='adminPage.php'; (???).userMenus.location.href='userMenus.php'\"
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

suggestion: you should use a top level admin page that contains the frameset for the admin area. Common functionality and information can be stored in the top level admin page.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

I dont know whether I understood you...
do you mean to create an adminMainPage which holds two frames and has adminMenus.php and adminPage.php in it.
I earlier thought of it. but thought why I need two top level pages for user and admin?? why dont we load pages accordingly in one top level page??

But is not possible to do wot I asked you in my earlier post??
Last edited by raghavan20 on Mon Aug 29, 2005 7:32 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it is, but the code needs to be inside the top level parent, not in a child frame.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

simply replace your ???? with top and thatsit...
feyd wrote:but the code needs to be inside the top level parent, not in a child frame
the above code with ???? replaced with top, will work from anywhere...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

not necessarily. The object heirarchy may change, creating a script error if done from a child frame. The change should be performed by the top parent to be safe.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

feyd wrote:not necessarily. The object heirarchy may change, creating a script error if done from a child frame. The change should be performed by the top parent to be safe.
I agree. But if the object heirarchy changes, would not there be error when accessing from parent frame too :?:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

not unless the entire document changes. Accessing siblings isn't a good idea, but accessing children and parens is fine.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

I tried this but does not work instead it opens the index.php page with the userMenus.php on 'userMenus' frame and another page on 'mainFrame' frame.

Code: Select all

<a href = 'index.php' target='_self' onclick=\"top.mainFrame.location.href='adminPage.php'; top.userMenus.location.href='adminMenus.php'\">
I have made it work in another way

Code: Select all

//homePage.php
<a href = 'index.php?action=openPages&category=admin' >Admin Page</a>

Code: Select all

//index.php
<frameset cols="23%,80%" >
<?php
if (isset($_GET["action"])){
	if($_GET["action"] == "openPages" && $_GET["category"] == "admin"){
?>
	<frame src="adminMenus.php" name = "userMenus"/>
	<frame src="adminPage.php" name = "mainFrame"/>
<?php	
	}
}else{
?>
	<frame src="userMenus.php" name = "userMenus"/>
	<frame src="listBlogs.php" name = "mainFrame"/>
<?php
}
?>
</frameset>
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

raghavan20 wrote:I tried this but does not work instead it opens the index.php page with the userMenus.php on 'userMenus' frame and another page on 'mainFrame' frame.
It wont, because of the way you have done it. This code

Code: Select all

<a href = 'index.php' target='_self' onclick="top.mainFrame.location.href='adminPage.php'; top.userMenus.location.href='adminMenus.php'">
loads index.php into _self which is mainFrame, hence the oddity. if you had chaged href="index.php" to href="#" and removed target bit, it would have worked perfectly.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

It does not change even then
http://raghavan.allhyper.com/homePage.php#
username and password: visitor (each)
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

*sigh* this is so because there is no userMenus or mainFrame frames on this page. you need to have frames in place for this code to work. If you want to transit from a no=frame page to the one with frames, you are better off continuing with your temporary arrangement that you talked in few posts back.
Post Reply