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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find out the name of a Frame?

Status
Not open for further replies.

thebigf

Programmer
Dec 12, 2000
14
AT
I'm writing a pagemirroring system for online shops.

So I have onChange or onClick handlers for every form element that send the event to a servlet on the mirrored page. On the other side there is a polling applet that fetches these events from the servlet and creates javascript instructions that manipulate the elements on the page that mirrors.

My problem is that if my pages use frames (and the mirroring applet is in an own frame) i have to write the complete path to the element e.g. parent.framename.document.formname.element.value="whatever"; (because of netscape I can't use the all object)

But how can I find out the name of the frame (formname is easy, its an element of the element object) on the mirrored page (that one that calls the JavaScript handlers).

Anyone any ideas?
Thanx
thebigf
 
Well, you can name your frame in your frameset. Then simply call it by that name in your JavaScript.

Also, the window object has a frames array which you can access by number. So, in the order that they were declared in your frameset, the frame which you might call frame2 could be accessed via parent.frame2 or via parent.frames[1] (it's a zero-based array).

Hope that helps.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Sorry,... I think you didn't understand my problem.

I transfer the name of the element + values to my Applet. The applets send the info to a servlet. This servlet parses the info to an applet on an other computer. There a javascript command is generated that restores the value on the other computers page (mirroring every action of the customer for the helpdesk assistant). It works fine in a frame, but if there are more frames I have to know the frame name. Problem: All pages are generated dynamically and the event handlers are added by a speciall filtering servlet before delivery to the browser only if mirroring is activated. So I can't hardcode the framenames.

example of my pages (currently without frames):

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function ProcessEvent(element){
if(element.type!=&quot;select-one&quot;)
document.applets[0].setEvent(element.name,element.type,element.value,element.checked);
else
document.applets[0].setEvent(element.name,element.type,element.options.selectedIndex,element.value);}
</SCRIPT>

<FORM name=&quot;HTMLParserForm0&quot;>
<INPUT NAME=&quot;Amount1&quot; TYPE=TEXT VALUE=&quot;1&quot; SIZE=2 onchange=&quot;ProcessEvent(window.document.HTMLParserForm0.Amount1);&quot;>
Pieces
</FORM>

The eventhandler is created dynamically at runtime by a servlet.

Ideas?
thebigf
 
if you have a way to know in which order they are created, then you can refer them as document.forms[index], and then get the name with document.forms[index].name
 
That's one of my problems. I don't know because everything is created dynamically.

@iza
How will you find out from which frame the event handler was called? If I would know, I wouldn't need the name, the index would be enough. But I simply don't know a way to find out the frame of an element if you only have the element object. They only thing I thougt of was parsing all frames and their forms for the element name but that would mean that the element name has to be unique to ALL the frames. Also this is not a really good solution because in the worst case I would parse all elements on the page. There must be a better way

thx
thebigf
 
&quot;How will you find out from which frame the event handler was called ?&quot; --> i don't even know if it's feasible ... maybe looping thru all frames asking if (event==frame[index].event) ????
&quot;But I simply don't know a way to find out the frame of an element if you only have the element object. &quot; --> i don't see anything else than looping as above (using object instead of event) - document.top and document.opener are the only properties i know to refer to an &quot;upper&quot; object ...

btw there was a thread (if i remember, in this forum) of someone who had 2 frames and was looking for a way to retrieve for an object to which frame it belonged - don't know how it ended up ...
 
I solved my problem.

With self.name you get the name of the frame that called the event handler.

thx
thebigf
 
don't you get the name of the object you're on, with self.name ??
 
No it's the name of the frame. I've checked that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top