posted by
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 :-(
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.