Frame's Parent Name

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Frame's Parent Name

Post by anjanesh »

I have this in index.php

Code: Select all

<FRAMESET COLS="150,*" NAME="frameMain">
<FRAME NAME="frameLeft" SRC="Left.php">
<FRAME NAME="frameMiddle" SRC="Middle.php">
</FRAMESET>
Left.php contains the list of menu items. frameMiddle varies. Initially its Middle.php but when clicking a link on left it changes. For Ex. Banners.php. But I dont want anybody to enter Banner.php in the url. If he does so it'll automatically load index with Banner.php as Middle.

I tried client side checking but document.write(window.parent.frameName); is giving undefined. FRAMESET doesn't seem to support NAME property but then how else to overcome this ?
Last edited by anjanesh on Tue Dec 27, 2005 4:38 am, edited 1 time in total.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

As far as I know there is no way to add a name. The question is why would you want to ?

If needed for javascript window.top relates to the top frame/window.
If usng HTML The form target should be set to <form target="_top">.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Well. What I dont want is user to enter Banner.php in the address bar of their browser and have that page loaded separately. If at all someone does enter Banners.php in the address bar then it should automatically load the frame page with Banner.php as Middle. If you look at MSDN and save a particular topic from the library to your hdd and then try opening the content page (which is in subfolder : right->content) it'll load the frame page automatically.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

In javascript you could apply an onload event to check the frame name,

Code: Select all

if (typeof window.name == undefined) &#123;
  //reload main frame
&#125;
No matter what there are easy ways around it. (Switching off javascript for one).

Another alternative is to not use frames and use a CSS layout instead. Unfortunately if you are in development rather than design this would mean a substantial rework. :(
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Another method is to use HTTP_REFERRER to find out which script is calling it but unfortunately not all browsers send this data.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Another solution. For your subpage stick onload event to

Code: Select all

if (window == top) top.location.href = "topframe.html";
Post Reply