Forum Moderators: open

Message Too Old, No Replies

IFrames Help

Hyperlink code to iframe page?

         

KCBlueGal

5:21 am on Nov 12, 2004 (gmt 0)

10+ Year Member



I'm very new to this and am looking for assistance on Iframes. I'm not having much luck googling or searching this site.

I have a plain index page with hyperlinks. Then I have an index2 page with nothing but a navigational bar.

What I want is each hyperlink on index.html to point specifically to a certain iframe. For instance, if I have a "Contact Me" hyperlink on index.html, I want index2.html to pop up, with contact.html in its own iframe. Since I have multiple links on index.html, I want each hyperlink to load index2.html with its corresponding iframe.

Is there some kind of target tag I'm missing?

moltar

5:43 am on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are exactly right :) You need to specify a target attribute to the <a> tag and name attribute to your frame tag.

<a href="..." target="my_iframe_name">blah</a>

and then

<iframe name="my_iframe_name" ... ></iframe>

KCBlueGal

6:00 am on Nov 12, 2004 (gmt 0)

10+ Year Member



Either I'm doing something wrong or I'm just not getting it.

Here is my tag on index.html:

<A HREF="showroom.html" target="main"><IMG NAME="front2" SRC="front_2x1.jpg" WIDTH="155" HEIGHT="43" BORDER="0"></A>

What I need is:
From index.html, click on the Showroom link, have index2.html pull up with showroom.html in its respective iframe. I already have the iframe working in index2.html, but am having problems linking it from the NON-iframed page (index.html).

I understand the iframe tag above, but where do I put it, in the case I just described?

tedster

6:27 am on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for joining us, KCBlueGal. You are going to need some scripting to carry name of the page to load in the iframe over to index2.html from index1.html - javascript will work.

SAMPLE LINK ON index.html

<a href="index2.html?showroom.html>Showroom</a>

SCRIPT IN THE <HEAD> OF index2.html

<script type=text/javascript>
origURL = parent.document.URL
iframeURL = origURL.substring(origURL.indexOf('?')+1, origURL.length)
</script>

IFRAME CODE IN THE <BODY> OF index2.html

document.write("<iframe src=\"' + iframeURL + '\" name=\"myiframe\" height=\"200\" width=\"300\"></iframe>")

Just add in your iframe attributes, but use a backslash [\] before every quotation mark. That's called "escaping" -- so the script knows you really mean "write in a quotation mark here" instead of "end the document.write() here".

Your links that are already ON index2.html just need to use the target attribute:

LINK IN THE BODY OF index2.html

<a href="showroom.html" target="myiframe">Showroom</a>

-- Now that you have an answer, can I talk you out of that kind of design? For instance, what happens if someone comes to the iframed page directly, instead of loaded in the iframe on its parent page - called an "orphaned" page? How are people going to bookmark specific iframed content if they want to? How will your visitors see WHICH link they just loaded (that's called a location cue)?

There are many complications and drawbacks to this kind of interface.

KCBlueGal

9:10 am on Nov 13, 2004 (gmt 0)

10+ Year Member



Thank you for your response and gentle nudging. ;-)

I understand the pros and cons of all web design... it just so happens that inline frames will be the best solution for the layout I need this site to have. I already had plans to attempt to fix a couple of the issues that iframes presents.

tedster

10:40 am on Nov 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As long as you're aware of the downside, and especially since you have plans to handle the drawbacks, frames and iframes do have value.

I've tested over and over and found that I almost always get better results by avoiding both of them - and still I have a couple pages with big fat framesets because they really are a good tool for the particular job I need to get done. So I completely understand.