bugshaw: (Default)
Add MemoryShare This Entry
posted by [personal profile] bugshaw at 02:58pm on 10/08/2004
I have a Javascript/frames problem and I'm blowed if I can sort it out. Anyone able to give me a quick pointer?

I have a home page - index.htm - with frames with links to various documents.
When you open index.htm it loads the document main.html (an intro page) into frame FContents. When you click links (in nav bars etc) to pages on the site, they are also opened in frame FContents (using a href="content_page.html" target="FContents"). So far, everything is going according to plan.

However, when someone opens a page directly e.g. "http://www.domain.com/pages/content_page.html" it does not open within the frameset and so lacks context.
I can detect whether the page is unframed [using JavaScript: if (self==top) ] but then comes the part I have trouble with. I want to alter the display of content_page.html depending on its framedness.

a) Ideally if (self==top) open content_page.html in frame FContents of page index.htm
- something like if (self==top) self.location.href="index.htm";
- but I can't see how to get content_page.html passed into frame FContents, it just brings up the starting frame src as given in index.htm.

b) Alternatively, show an image at the top of content_page.html if unframed - this would have the logo, a few words of context, and a link to index.htm and one (if poss) to index.htm with content_page.html loaded in frame FContents
Here I have got as far as creating a string variable which writes a line on the top of the page depending on frame status.
- var msg="Framed";
- if (self==top) msg="Unframed";
- document.writeln(msg);

What I think I want to do is use this function to change the src of an image in the body text - or to "write" the image to the top of the page as with writeln(). But again, I can't get the parameter to pass properly. I've tried various things like:

var PicName="../images/blank.gif";
if (self==top) PicName="../images/logo.gif";

document.FrameImage.src=PicName;

and then in the body

img src=PicName name="FrameImage"


This would seem like a common thing to want to do, but I'm finding it very difficult. Hints welcome :-(
There are 17 comments on this entry. (Reply.)
 
posted by [identity profile] hawkida.livejournal.com at 07:10am on 10/08/2004
Don't have time to read your msg properly right now, unfortunately. Hope you get some help soon. But I just thought I'd point out that this is one of many reasons why frames are generally considered evil and to be avoided if at all possible. For a start, what if someone turns of javascript? They're not going to get in at all. And then there are all the bookmarking and back button issues...

Hmm... one possible hint pointer that might be useless. I think Raz did some stuff like this on his sites in the past. Have a look at http://matrixcity.org at the Red Dwarf section in particular and dig around the source code. No promises it'll help but it might in the absence of any direct advice.
 
posted by [identity profile] bugshaw.livejournal.com at 07:41am on 10/08/2004
Same problem I've got I'm afraid (if he thinks it's a problem). If you browse direct to http://www.matrixcity.org/red-dwarf/core/introduction.html you get a standalone page, no links back to home, no context other than the page content. And search engines often link to pages like that which don't go anywhere. I want it to appear in a relevant frame...
 
posted by [identity profile] hawkida.livejournal.com at 07:51am on 10/08/2004
Oh, I thought he'd done clever wizardry to overcome that. Ah well.
 
posted by [identity profile] ramtops.livejournal.com at 07:13am on 10/08/2004
my first question would be "why frames?" - they're horrible, and this is one of the reasons why!

[livejournal.com profile] perlmonger is my in-house javascript guru, and he's really really busy right now. But he asks if you have anything available server side ...

but we both think you should just lose the frames :)
 
posted by [identity profile] bugshaw.livejournal.com at 07:35am on 10/08/2004
Because, frames. At some point in the future it may be possible to spend time changing the entire site to avoid frames (sigh - big rant about evilness of frames cut for space and time), but the big priority is that given that we are using frames and javascript, we want subpages to open with adequate accompanying context.

Could do something server-side I expect - that's not my area of experience at all though!
 
posted by [identity profile] ramtops.livejournal.com at 07:46am on 10/08/2004
what do you have available server side? He might manage to reply to you this evening, but we have far too much to do right now, sorree ...
 
posted by [identity profile] bugshaw.livejournal.com at 07:53am on 10/08/2004
What do you have available server side?
Thanks for the thought, but I don't have the knowledge/easy access to person with smattering of knowledge to even be able to answer the question, so I doubt a server side solution would be implementable in the desired timescale (day or two). :-(
 
posted by [identity profile] ramtops.livejournal.com at 08:06am on 10/08/2004
bugger
 
posted by [identity profile] alexmc.livejournal.com at 07:30am on 10/08/2004
Frames bad. No no no.

Use css. It may be harder to learn but it will make you look all whizzy and will be a more generic solution

 
posted by [identity profile] mr-tom.livejournal.com at 07:36am on 10/08/2004
I'm not much of a web guru, so feel free to ignore the following totally:

* Could you check to see if the referrer ID is domain.com, and if not, open the frameset instead of the content in the frame. Like this: http://developer.irt.org/script/143.htm. (Actually, that syntax may do for what you need anyway...)

* Kludgy fix: make the menu links open the whole frameset+ relevant content in the main window. Not a good one if you have a lot of traffic, I suppose.
 
posted by [identity profile] bugshaw.livejournal.com at 08:01am on 10/08/2004
Arg - nearly! I can get it to go to the relevant index page, but how do I tell index.htm that I want frame FContents in index.htm to contain content_page.html instead of generic_intro_page.html?

I need a clever wizard.
 
posted by [identity profile] mr-tom.livejournal.com at 08:14am on 10/08/2004
Depending on how many pages you have: make more index pages. :-)

Either that, or you may be able to use currenturl. So you request a deep-link, which returns a frameset with the requested url as one of the frames...
 
posted by [identity profile] bugshaw.livejournal.com at 08:38am on 10/08/2004
Depending on how many pages you have: make more index pages. :-)

Do not jest, sir! (We have 30 index pages but over 100 pages...)

currenturl/deep-link looks v. promising, oh web guru. I shall investigate - thanks!
 
posted by [identity profile] blufive.livejournal.com at 12:24pm on 10/08/2004
This looks pretty close to what you're after:
http://www.sitepoint.com/forums/showpost.php?p=651647&postcount=4

I find sitepoint a good place to go looking for this sort of thing - they have a fairly decent signal/noise ratio for online forums
 
posted by [identity profile] calatrice.livejournal.com at 01:15pm on 10/08/2004
I haven't done the frames redirect trick for years now, but one thing that used to catch me out on a regular basis is that the redirection script I had used to only work if the pages were on a webserver. According to Gav this is something to do with the difference between accessing the page via the http protocol and just reading it off your hard drive.

I'm not sure if this still holds true, but essentially if the pages were on a boring old PC, then Windows would not pass the part of the url after the '?' in the script in the content page. Hence the script would never pick up the bit about displaying the desired content page within the frameset.

This typically resulted in me puzzling over the pages for hours before I remembered to try an uploaded version.

The script I used to use had two parts - one in the content pages that you wanted to put in the frameset and a second one in the frameset page which dynamically drew the frameset. You can find an example here:

http://www.chalcedony.com/javascript3e/scripts/script04.03.html

Incidentally, I would really recommend the book - "JavaScript for the World Wide Web". I've used it a lot over the years (I have the third edition) and find it really helpful, especially as I'm not a very good programmer.
 
posted by [identity profile] red-cloud.livejournal.com at 05:36pm on 10/08/2004
I concur. This is the canonical example from Negrino & Smith (http://www.amazon.co.uk/exec/obidos/ASIN/032119439X/oakhouse-21). It does exactly what it says on the tin.
 
posted by [identity profile] bugshaw.livejournal.com at 11:31pm on 10/08/2004
Ahhhh-HA! When in doubt, ask the CAL9000. That looks very much like The Thing - plus the web vs hard drive thing.

Bleugh - not enough sleep. Must go to work. More thanks later once suggestions implemented!

September

SunMonTueWedThuFriSat
  1
 
2
 
3
 
4
 
5
 
6
 
7
 
8
 
9
 
10
 
11
 
12
 
13
 
14
 
15
 
16
 
17
 
18
 
19
 
20
 
21 22
 
23
 
24
 
25
 
26
 
27
 
28
 
29
 
30