Javascript/Frames problem
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 :-(
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 :-(

no subject
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.
no subject
no subject
no subject
but we both think you should just lose the frames :)
"Why frames?"
Could do something server-side I expect - that's not my area of experience at all though!
no subject
no subject
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). :-(
no subject
no subject
Use css. It may be harder to learn but it will make you look all whizzy and will be a more generic solution
no subject
* 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.
no subject
I need a clever wizard.
no subject
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...
no subject
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!
no subject
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
no subject
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.
no subject
no subject
Bleugh - not enough sleep. Must go to work. More thanks later once suggestions implemented!