Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

iframe (LINKS)

Status
Not open for further replies.

ebase

MIS
Jan 7, 2004
40
US
iframe questions (LINK)
Hello,

I have a questions about links and iframes. I am trying to create a link that goes to for example which uses iframes. Depending on the link, I would like to have a different page show up in the iframe of How would I go about doing this?

For example:

"a.com link 1" goes to a.com with 1.html loaded into the iframe.

"a.com link 2" goes to a.com with 2.html loaded into the iframe.

and so on. Is this even possible or would I have to use JavaScript? Any information would be greatly apreciated! Thanks!

Kei
 
AFAIK this can't be done. IFrames have the same problem as frames -- you cannot access specific pages within the frameset (or page with an iframe).
 
Vragabond, I don't think that's the question Kei is asking.

Kei, call the URL of a.htm like: or
Then, in a.htm, read the URL and determine what value is associated with the URL parameter 'ifr'. Set this value to some global JavaScript var ifrId (for example).

When it comes time to add the IFRAME to the HTML, insert a SCRIPT section as:

Code:
<script>
if(ifrId == 1)
 document.write("<iframe id='myIframe' src='[b]1[/b].htm'></iframe>");
else //ifrId == 2
 document.write("<iframe id='myIframe' src='[b]2[/b].htm'></iframe>");
</script>

Is that what you're after?

'hope that helps.

--Dave
 
Thanks LookingForInfo,

My example is below:

main.html has 2 links
1 - 2 -
Then in a.htm, I added:

<script>
if(ifrId == 1)
document.write("<iframe id='myIframe' src='1.htm'></iframe>");
else //ifrId == 2
document.write("<iframe id='myIframe' src='2.htm'></iframe>");
</script>

When a.htm loads, there is a JavaScript error that says 'ifrId' is undefined. I am assuming that this is happening because I did not set this value to a global JavaScript var, ifrId. I am new to this and would really appreciate it if you can tell me how.

Thanks in advance! I really appreciate the help!
Kei
 
Try adding this to the top of your document:

Code:
<head>
<script>
var ifrId = (document.location.href.split("="))[1];
</script>
</head>

This takes the URL (document.location.href) and loads it into an array (.split("=")). The first element of the array (the zero-index)is everything before the "=" sign and the second element (the [1]-index) is everything afterward (in this case, a 1 or a 2). At this point, therefore, ifrId will be equal to 1 or 2.

'hope that helps!

--Dave
 
Would I be right in guessing that the page with the <iframe> tag in it is a template page with the site name and navigation and so on, whilst the pages that are displayed in the <iframe> have that actual content of the site?

If so, by using Javascript to control the display and content of the <iframe> you are hiding your most important text from the search engines. There are also people who surf with Javascript switched off who won't be able to use your site.

Consider losing the <iframe> and use a scrolling <div> instead. See my post at the end of Thread253-881817 .

-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top