homepage Welcome to WebmasterWorld Guest from 54.196.24.103
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Force into Frames - JavaScript magic
one frameset page works for many orphan pages
tedster




msg:1474407
 3:31 am on Nov 13, 2001 (gmt 0)

I avoid using frames, so I've never given much focus to forcing specific orphan pages into their frameset before. I always suggested creating a new frameset document for each orphan page. But I recently inherited a framed splendor of a site, so I had to focus.

Here's the good news you can add ANY page's name to the end of a URL [after a "?"] Then you only need ONE frameset page to catch an indefinite number of orphan pages and put them into their frameset. This method offer very easy maintenance, especially when there are lots and lots of possible orphans for one frameset.

_____

Call this javascript code from the HEAD section of each child page. The code creates a variable from the URL of the page, and then passes that variable in the new location's URL. This means a "master" frameset can load this exact page in the content section:

passpage = document.URL
if (top.location == self.location)
top.location.href="master.html?" + passpage

Then create just one "master.html" page. It holds the JavaScript code to decipher whatever URL is passed after the "?" and it writes that page into the content frame:

<html>
<head>
<title>Master Frameset</title>
</head>

<script language="JavaScript" type="text/javascript">

origURL = parent.document.URL
contentURL = origURL.substring(origURL.indexOf('?')+1, origURL.length)

document.write('<frameset cols="20%,80%"><frame src="leftnav.html" name="nav"><frame src="' + contentURL + '" name="content"><\/frameset>')

</script>

</html>

I feel like it's Christmas!

 

toolman




msg:1474408
 4:38 am on Nov 13, 2001 (gmt 0)

Christmas indeed!

Merry Christmas to you tedster...and thanks. Great tip.

idiotgirl




msg:1474409
 9:38 pm on Nov 13, 2001 (gmt 0)

I did a similar little js like this because I had so many pages grabbed by SE's that obviously became orphans when viewed through SE results.

I created a little snippet called orphans.html and added it into the <head> section via SSI call using HomeSite's global find-and-replace to all the possible orphan pages (180+ pages in about 5 minutes) :).

That way, if my frameset params changed (but of course they did!), I needed only to change master.html and the whole site was updated.

spookycam




msg:1474410
 1:01 am on Apr 1, 2002 (gmt 0)

Wonderful but hmmmmm I wonder if there's a way to hide the messy URL from users- people get confused easily.

Also, nested frames. Heh. I am the queen of frames and have left AND top nav bars on some pages. Never did get the above to successfully process 2 frames layers. Is there something obvious I am missing? ;>

tedster




msg:1474411
 5:09 am on Apr 1, 2002 (gmt 0)

Welcome to the boards, spookycam. When you nest frames you definitely buy yourself some challenges, don't you? :)

On any given frame page, you already would know what URLs you want to load into the other frames, right? Seems to me you still only need to pass one variable - the page the vistor has landed on. You would include the other URLs you want to load in the code of "Master Frameset" document, inside the document.write().

Hiding those messy URLs? Not with Javascript as far as I can see. It feels like there may be a server side method, but I'm not very strong there.

Any ideas, anyone?

allybongo




msg:1474412
 9:22 am on Sep 25, 2002 (gmt 0)

Hi Tedster!

Ignore this message! Had a flash of inspiration! It now works, thanks for the code tedster. :)

Not sure whether you will check this thread again but here goes.

I've just found your code for regenerating the frameset if an orphan page is loaded.

Everything is working fine except the frame I am trying to load into is blank. The navigation and footer frames load in fine its just the frame that loads the orphan page that wont show. When I do a properties check it comes up as about:blank

I have put in this code in the master.html

<script language="JavaScript" type="text/javascript">

origURL = parent.document.URL
contentURL = origURL.substring(origURL.indexOf('?')+1, origURL.length)

document.write('<frameset rows="135,1*,134" cols="*" frameborder="NO" border="0"

framespacing="0">')

document.write('<frame src="navigation_bar.html" name="navigation" scrolling="NO"

frameborder="NO" marginheight="0" marginwidth="0" noresize>')
document.write('<frameset cols="1*,800,1*" frameborder="NO" border="0"

framespacing="0" rows="*">')

document.write('<frame src="../general_pages/blank.html" name="blank">')

document.write('<frame src="' + contentURL + '" name="content2">')

document.write('<frame src="../general_pages/blank.html" name="blank">')

document.write('</frameset><frame src="footer_v2.html" name="footer" scrolling="NO"

noresize></frameset>')

</script>

and this code in the head of the orphan page

<script language="JavaScript">

passpage = document.URL
if (top.location == self.location)
top.location.href="master.html?" + passpage

</script>

I've looked at this for hours now but not being that good at Javascript its hopeless.

Thanks in advance!

korkus2000




msg:1474413
 12:58 pm on Sep 25, 2002 (gmt 0)

Does your content URL need a ../ before it to work?

document.write('<frame src="../' + contentURL + '" name="content2">')

all of the other urls had this so maybe this one does to?

allybongo




msg:1474414
 8:34 am on Sep 26, 2002 (gmt 0)

thanks Korkus for replying, but I managed to get it to work. For some reason it didnt work on my mac but when I'd ftp'd it, it worked!

Thanks to Tedster for the code!

aspr1n




msg:1474415
 8:43 pm on Sep 26, 2002 (gmt 0)

tedster,

as cool as this solution is, there are two minor problems with it.

Firstly, it allows the less scrupulous to frame jam one of your pages in their frame.
Secondly using the document.write won't work for iframe with URLs.

My preferred solution is similar but fixes above:

In the child head content:


<script language="javascript" type="text/javascript">
if (window.name!='Content' && window.name!='booker_' && !((self.innerHeight == 0) && (self.innerWidth == 0)))
top.location.replace('master.html?' + self.location);
</script>

Have the master reference the following:


function frameParent(){
thePage = location.search;
if ( thePage.length < 2 ){
thePage = 'YourFullURL';
}
else
thePage = thePage.substring(1);
top.Content.location = thePage;
}

Call in the master body after the frame declaration eg:


<iFrame id="Frame" frameborder="0" name="Content" src=""></iFrame>
<script type="text/javascript" language="javascript">
frameParent();
</script>

Basically, the Child checks to ensure it is allowed to be in that frame , and checks to ensure it's currently not framed.

For pages with multiple frames, you could just pass the default URL into the function as an argument.

asp

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved