PDA

View Full Version : Hyperlink to open page and specify iframe source


Windle Poons
27th Sep 2004, 16:09
A cry for help.....

I am trying to set up a series of menu items on a web page that all link to the same page which contains an iframe. No problem there, but I need each of the menu options to load the page and specify the initial source for the iframe, such that it is relevant to the option selected.

I have experimented with various script and attribute options, but have failed abysmally to date. I am probably missing something really obvious, or am in search of something akin to the Holy Grail.

If anyone knows of a way to do this, or can point me in the right direction I would be extremely grateful.

WP http://www.bazlinton.com/images/41616-4.gif

E-Liam
27th Sep 2004, 18:48
Hi WP,

Not really my area, but you could try having a look at the code on a webpage that alraedy has what you are after. Not much I know.. :)

Cheers

Liam

Windle Poons
27th Sep 2004, 19:24
Hi E-Liam,

I am still googling for a similar site or a script, and if I find anything then I'll post it for reference. As an aside I heard that email has now been accepted into the english dictionary as a word, so it can drop the hyphen. ;) I only mention it in case you want to change yours by deed poll to reflect this! Have Fun...

WP.

Memetic
28th Sep 2004, 15:01
Have you considered not using frames? I seem to remember iframes were only compatible with internet explorer.

Also frames can be a pain for search engine listing, people who find framed content come in on the frame not the site so can not easily navigate etc.

Not so great for some mobile browsers either.

I am managing get by with using tables and .php includes. It might not be the answer for you, and is certainly not the answer to your question, but may be worth considering.

Perhaps if you could post a chunk of sample code or a link to a test page one of us woudl be able to help more.

Memetic.

UPDATE:

Thinking about this the only way I can see to do it with iframe is to have a different page containing the iframe for each menu item, as you need to specify the target url for the frame on the page being called not in the menu link. Obvioulsy each url in the separate iframes can call a different section of the document in the frame using the name attribute in the anchor.

That assumes of course that you control the document being framed so that you can add the anchors and know that they will not change.

Not hard to do, a copy and paste job, but it does requre a few more files. SHould not need much more space though as all graphics are shared and the framed document is common to all.

Naples Air Center, Inc.
29th Sep 2004, 03:53
Windle Poons

You should be able to find many alternatives at:

Hot Scripts (http://www.hotscripts.com/)

Take Care,

Richard

Windle Poons
29th Sep 2004, 10:49
Memetic, I think we have similar feelings about use of frames, and I would love not to use them here, but the site is for someone that will need to update the site on their own, and who is a complete technophobe.

There are many ways to skin the cat, but iframes allow me to use pages with minimal html, or even notepad/word documents with no html at all, inside a parent page. My technophobe friend can then just create or change simple html pages or notepad/word documents to update the relevant portion of the pages without fear of changing the html coding for the site.

For browsers that do not support iframes I have included all the text and images in the 'Alternative Content' portion of the iframe.

The reason for needing this script is that the home/index page has a different layout to all the others. I could use multiple pages, and multiple iframes, but that is extra work and not quite so neat.

Plus and this is probably the truth of it, I was too stubborn to give up once the problem had present itself.

At long last however I have found a solution. Hot Scripts didn't have the actual solution, but whilst searching their site I did find a cunning little piece of script that assisted greatly (thanks Richard - NAC, Inc).

I post the solution here in case anyone else wishes to use it.

On the index page use the following script within the HEAD section:

***********************

<script language="JavaScript" type="text/JavaScript">
<!--
function loadIframe(iframeName, url) {
if ( window.frames[iframeName] ) {
window.frames[iframeName].location = url;
return false;
}
else return true;
}
//-->
</script>

***********************

The hyperlinks on the index page then need to be in the following form:

***********************

<a href="index2.html?contact.htm">Contact Us</a>


***********************

Where index2.html is the target parent page and contact.htm is the page or document to appear in the iframe.

Then on the target page (index2.html) you need first to place the following script in the HEAD section


***********************

<script language="JavaScript">
<!--
var newURL = unescape(location.search.substring(1));
//-->
</script>

***********************

and then change the <BODY> tag so that it is in the following format:

***********************

<body onload="if (newURL !='') parent.text.location.href=newURL">

***********************

where text is the name of the iframe.

Thank you again for you help and advice. :ok:

A much happier WP.
Still as stubborn though! ;)

Memetic
29th Sep 2004, 12:16
Glad to see you cracked it, for me Java script is very much a cut paste and tinker language rather than something I actually have a clue about.


I would love not to use them here, but the site is for someone that will need to update the site on their own, and who is a complete technophobe.


If you / the site manager has a small budget for tools other than note pad you may want to consider Contribute (http://www.macromedia.com/software/contribute/solutions/agencies_developers/index.html) which seems to do a good job of letting people update sites whilst protecting them from themselves.

Plus and this is probably the truth of it, I was too stubborn to give up once the problem had present itself.

A good trait! IMHO :D

Windle Poons
29th Sep 2004, 16:46
Memetic, thanks for the tip. I have downloaded the free trial version to have a look at, and will probably suggest it to a few people as well. :ok:

Ah well enough of computers and back to the day job....

WP

Naples Air Center, Inc.
2nd Oct 2004, 21:39
Windle Poons,

Glad it worked out for you.

Take Care,

Richad