Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get this frame's name in my javascript code

this is my html code :

<frameset rows="18,*" frameborder=0 framespacing=0>
    <frame src="/zh-cn/MapS/MainTop/" noresize scrolling=no>
   <frameset cols="0,*,210" name="menu">
     <frame src="/zh-cn/MapS/MainLeft/" scrolling=no noresize>
     <frame src="/zh-cn/MapS/Watch/" name="desk">
     <frame src="/zh-cn/MapS/RightMenu/" scrolling=no noresize>
    </frameset>
  </frameset>

and this is the javascript code in on frame :

parent.parent.frames[2].frames[0]

i want to know which name is this frame ,

i do this :

console.log(parent.parent.frames[2].frames[0].nodename)

it show:

undefined

so what can i do ,

thanks

like image 548
zjm1126 Avatar asked Sep 18 '25 04:09

zjm1126


2 Answers

For example, this should work

window.frameElement.name

Also, if all you have is a reference to an element inside a frame and want to know the frame name this element belongs to:

document.getElementsByTagName("body")[0].ownerDocument.defaultView.window.frameElement.name
like image 173
Mariusz Avatar answered Sep 19 '25 16:09

Mariusz


Why are all the answers here so complicated ?

The name of the current document (== frame name) can be obtained via:

var sName = window.name;

If the current document is the root document or if the parent document has not assigned a name to the child frame, sName will be an empty string.

like image 40
Elmue Avatar answered Sep 19 '25 18:09

Elmue