Working with IFRAMES

james70

New Member
Messages
7
Reaction score
0
Points
0
I have a page with an IFRAME that points to another site. is there a way to create a link on a sperate page that would open the page with the IFRAME but change the content of the IFRAME?
 

wongers

New Member
Messages
431
Reaction score
5
Points
0
i think your referring to:
<a href="http://url.here" target="iFrame_name">Link</a>

from what you've described, you need the target="***" bit. the *** being the name of your iFrame.

if this isnt what your after, let me know and we'll discuss it :)
 

james70

New Member
Messages
7
Reaction score
0
Points
0
That's not really what I'm looking for. That works if the link and the frame are in the same .html file. Let me try to explain better. say I have a home.html file and a store.html file. The store.html has the frame that defaults to the store index page. I wnt to put a link on the home.html that points to the store.html but changes the content of the frame form the index page to a spacific product page.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
You can do it with .php files.

links:

store.php?q=apples
store.php?q= cherries

store.php puts out basically the same html it does now, just adjusting the src attribute in the IFRAME tag.

PHP:
<?php 
   if( isset( $_GET['q'] ) ){
         $src = $_GET['q'] . ".html" ;
   } else {
         $src = "default_product.html" ;
   }
?>

<iframe src="<?php echo $src ?>" width="100%" height="300">
  <p>Your browser does not support iframes.</p>
</iframe>
 

LostHorizon

Member
Messages
43
Reaction score
2
Points
8
Hi "james70",

If you want to use just HTML and JavaScript for your codes, try the followings:

  1. First, in your "home.html" HTML document, use "?url=some product.html" (it DOESN'T have to be "url=some product.html" specifically - I just use it as an example) in the HTML <A> tag after the link ("store.html") to pass the URL of the page that you want to show in your "store.html"'s <IFRAME> to the "store.html" HTML document,

    Code:
    <A href = "store.html[COLOR="red"]?url=some product.html[/COLOR]"></A>
  2. Second, in your "store.html" HTML document, use JavaScript to parse the "window.location.href"'s (or more specifically, "window.location.search" - don't know if this attribute/property is available in other browsers besides Microsoft Internet Explorer or not) result string to fetch the passed URL and feed it to the page's <IFRAME>'s src (let me know if you need further help on this).
Hope this helps.
 

james70

New Member
Messages
7
Reaction score
0
Points
0
Thanks. you've been a lot of help.
Below is the code I ended up using:

<iframe src="http://defaultpage" width="100%" height="850" id="inframe">
<p>Your browser does not support iframes.</p>
</iframe>

<script language="javascript" type="text/javascript">
var query = window.location.href.split("?");
var params = query[1].split("url=");
document.getElementById('inframe').src = params[1];
</script>


Link: <a href="http://mysite/?url=http://storesite/page">LINK</a>

I hope this helps someone else.
 

LostHorizon

Member
Messages
43
Reaction score
2
Points
8
Nicely done "james70",

Also, it's very NICE of you (very COMMENDABLE) to present the solution here as well so others can benefit from it.
 
Top