Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a html frameset frame tell its position on the page / in the window (through 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 @James K.

but what if both is not set?

is there anything 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 frames are not modern/historic - when this is not your thing please suggest a retro-section to stackoverflow rather than voting away the question?


1 Answers

In the way you're describing, no, you can't.

Well, you can, but if you want to do it entirely in javascript, you're going to have a challenge accounting for all of the variables involved (browser inconsistency, many different screen resolutions, workstations with several displays...). More discussion on that under "Difficult Answer" below.

Easy Answer:

The easiest way to do what you're trying to do is not entirely javascript, but rather the addition of the name parameter to the frame tag. So, as a very simplistic example:

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

From the perspective of the page running within each frame, the frame is the window object. Within each frame, you can call window.name and get the name you assigned.

That is, window.name will return "top" in the frame that has the name, "top".

I should probably note that this is not actually part of a javascript standard, but it works on all of the major browsers.

Difficult Answer:

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

I can elaborate on that if you need it, but it's definitely not a preferred method, especially in comparison to just naming the frames.

like image 59
James K. Avatar answered Nov 29 '25 05:11

James K.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!