Can the html frame frame indicate its position on the page / in the window (via javascript environment variable or otherwise)

Pesudo code:

If you are a frame that touches the right and the bottom of the window (/page/tab) 
(, then it is likely that you are a content area...)

If i am a frame that is on the left outline of window and of other frames 
(, then it is likely that i am a menu...)

      

In JS words:

I know self.location.match (/ (menu) / g)

  • and window.name.match (/ (menu) / g) thanks to @James K.

but what if both are not installed?

is there something like "self.position" ?

if(self.position.LeftNeighborOfOtherFrames&&self.position.window=left){...assume self is menu....}
else if(self.position = atRightOutlineOfWindow && atBottomOutlineOfWindow){...assuming content|page....} 
else if(self.positon.window=top){...assuming header...}
else if(self.position.window=bottom){...assuming footer...}

      

I know the framework is not modern / historical - if that's not your thing, please suggest a retro section for stackoverflow, not a vote from the question?

+3


source to share


1 answer


As you describe, no, you cannot.

Well, you can, but if you want to do it entirely in javascript, you will have a call that takes into account all the variables involved (browser inconsistency, many different screen resolutions, workstations with multiple displays ...). Further discussion of this issue in the "Difficult Answer" section below.

Simple answer:

The easiest way to do what you are trying to do is not really javascript, but adding a name parameter to the frame tag. So, as a very simplified example:

<frameset rows="40%, 60%">
    <frame src="top.html" name="top">
    <frame src="bottom.html" name="bottom">
</frameset>

      

From the point of view of the page being executed in each frame, the frame is an object window

. Within each frame, you can call window.name

and get the name you assigned.



That is, it window.name

will return "top" in a frame named "top".

I should probably point out that this is not actually part of the javascript standard, but it works in all major browsers.

Difficult answer:

You asked to do this entirely in javascript. The only way I can do this is to get the screen position of the parent window, the screen position of each frame, and possibly the overall display resolution, then effectively guess at each of the frames. Since I can't seriously recommend guesses, I don't really consider it a viable option. But, if you can't edit the frame names and actually need a solution for all javascript, maybe it is.

I can elaborate on this if you need it, but it is definitely not the preferred method, especially over simple frame notation.

+1


source







All Articles