Link to home
Start Free TrialLog in
Avatar of dtr
dtr

asked on

iframe content as defined by an external page

hi all,

i am trying to get an iframe on a page to display different content from different external pages. this is quite hard to explain so i will use an example:


page A contains an iframe. page B has a link to page A. Page C also has a link to page A. Pages B and C do not have an iframe and are seperate to page A. Pages D and E are to be displayed in the iframe.

When i click the link on page B i want page D to be displayed in the iframe but when i click the link from page C i want page E to be displayed. is there any way i can achieve this using javascript/html as opposed to php. i am working on an established site and so switching to anything other than javascript/html would be a huge pain!


i hope someone can help. many thanks,

dtr
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dtr
dtr

ASKER

have you tested this? i like the sound of the idea but i can't seem to get it to work.
I made some clarification changes, but functionally this should be the same.  This works in IE as tested:

pageA.htm:
  <HTML>
  <HEAD>
  <SCRIPT language="javascript">
   function querystring(name)   // returns a named value from the querystring
   {
      var tmp = unescape( location.search.substring(1) );
      var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");

      if ( i >= 0 )
      {
         tmp = tmp.substring( name.length+i+1 );
         i = tmp.indexOf("&");
         return( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));
      }

      return("");
   }

   function loadFrame(url)
   {
      if ( url && (url+="").length>0 )
         self.frames["myIFrame"].location=url;
   }

  </SCRIPT>
  </HEAD>

  <BODY onload='loadFrame(querystring("url"));'>
   <IFRAME name="myIFrame" id="myIFrame"></IFRAME>
  </BODY>
  </HTML>



pageB.htm:
  <HTML>
   <A href="pageA.htm?url=pageD.htm">A:D</A>
  </HTML>


pageC.htm:
  <HTML>
   <A href="pageA.htm?url=pageE.htm">A:E</A>
  </HTML>


pageD.htm:
  <HTML>
    page D
  </HTML>


pageE.htm:
  <HTML>
    page E
  </HTML>
start by opening pageB and pageC and clicking on the links.
Hi,


  if pageA's iframe is defined as:

<script>
function doit(url)
{
  if (url.length != 0)
     theFrame.location = url;
 }
</script>
<body onload="doit(location.search.substr(1))">

<iframe name='theFrame'></iframe>
</body>


pageB/C's links:

<a href="pageA.html?http://members.aol.com/grassblad">GrassBlade Javascript</a>

Vinny
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: knightEknight {http:#9599548} & VincentPuglia {http:#9599923}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

mplungjan
EE Cleanup Volunteer