Closed Thread Icon

Topic awaiting preservation: Passing data to an Iframe (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=25619" title="Pages that link to Topic awaiting preservation: Passing data to an Iframe (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Passing data to an Iframe <span class="small">(Page 1 of 1)</span>\

 
robur
Nervous Wreck (II) Inmate

From: Careywood, Idaho, USA
Insane since: Jan 2005

posted posted 04-26-2005 16:47

Hello everyone!

Today I am trying to pass data to an iframe from the parent window.

On my site at: http://www.safarri.com, there is an iframe containing a javascript tree menu with all the categories. Since I plan to have a lot of categories, I want people to be able to cache the category iframe. I also want the menu to open up to the category they last visited automatically.

Right now, I use the following code to initiate the menu from within the iframe:

<script type=\"text/javascript\" src=\"http://www.safarri.com/includes/dTree/dtree.js\"></script>
<script type=\"text/javascript\">
<!--
categories = new dTree('categories');
categories.config.closeSameLevel = true;

{$category List}

document.write(categories);
categories.openTo('.$_SESSION['safarriLastCategory'].', true);
//-->
</script>

My problem is the last line of JS. Since the users $_SESSION['safarriLastCategory'] is always changing, their browser can't cache the category list. What I am hoping is that there's a way to execute the categories.openTo('.$_SESSION['safarriLastCategory'].', true); from the calling window, so the user's browser can cache the category list.

Any suggestions would be appreciated!

-Robur

robur
Nervous Wreck (II) Inmate

From: Careywood, Idaho, USA
Insane since: Jan 2005

posted posted 04-26-2005 17:02

Sorry to post twice, but I've been thinking and here's what I've come up with as possible solutions:

1) I pass the user's "lastCategory" variable to to the iframe before it's built (possibly through a special iframe tag?), and the iframe figures out the rest.

2) I execute the categories.openTo('.$_SESSION['safarriLastCategory'].', true); from the parent window. (not sure if this is possible)

3) I set some "global javascript variable" that can be read by the iframe. (Note that I don't want to use cookies, as my site already sets one session cookie and I don't like bombarding the user.)

One to thing to note is that I can't pass any variables through the iframe's url, because the main goal of this hole thing is to get the browser to cache the category iframe.

After listing all these things, you're probably wondering why I didn't just do it myself. The reason is actually quite simple; I have practically no experience with JS.

Thank You,

-Robur

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-26-2005 17:58

Well you could pass the last Category to the iframe with the query string

Info Here

Or from the parent window something like so:

document.frames.[iframename].variablename



.:[ Never resist a perfect moment ]:.

robur
Nervous Wreck (II) Inmate

From: Careywood, Idaho, USA
Insane since: Jan 2005

posted posted 04-26-2005 18:30

Bitdamaged:

I definitley don't want to use the querystring, remember the whole purpose of this is to have the browser cache the iframe.

Your second example is (I think) just what I was looking for.
I will give a status report soon!

-Robur

reisio
Paranoid (IV) Inmate

From: Florida
Insane since: Mar 2005

posted posted 04-26-2005 18:42

Don't use frames.
Use SSI.

Problem solved.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 04-26-2005 19:03

[ ] - reisio has understood why robur wanted to use an iframe in the first place.


option 3 would be the way to go. Have a variable on/in the parent window, access that from the iframe,
output $_SESSION['lastCategory'] into that variable on page load -voila, user might be caching iframe contents.

so long,

->Tyberius Prime

robur
Nervous Wreck (II) Inmate

From: Careywood, Idaho, USA
Insane since: Jan 2005

posted posted 04-26-2005 20:31

Reisio:

Sorry, but I don't know anything about SSIs except that they stand for "Secure Socket Interface", or something like that.

Tyberius Prime:

That is exactly what i've been trying to do. The only problem is that I don't know how to do it :-) I'me not too good with Javascript, and the example BiTdAmAgEd gave triggered the error (in firefox) "document.frame is not a valid resource" or something like that.

What i really need to know is the way to pass data to a frame.

Thanks for all your help so far!

-Robur

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 04-26-2005 20:54

SSI = Server Side Includes
http://www.gurusnetwork.com/tutorial/server_side_includes/

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-26-2005 20:59

You are going to get this error if you are trying to change the variable before the page/iframe loads. You can add an iframe onload event handler to do this.

Check out this tute



.:[ Never resist a perfect moment ]:.

robur
Nervous Wreck (II) Inmate

From: Careywood, Idaho, USA
Insane since: Jan 2005

posted posted 04-26-2005 22:07

After reading the tutorial refrenced by BitDamaged, I got it working!

The code I used on the parent page is:

<input type="hidden" value="<?=$_SESSION['safarriLastCategory']?>" id="lastCategoryID" />
<iframe src="/classifieds/templates/categoryTree.php" name="cTree" id="cTree" width="180" marginwidth="0" height="300" marginheight="0" align="top" scrolling="auto" frameborder="0" /></iframe>

and the code I used on the iframe is:

lastCategory = parent.document.getElementById('lastCategoryID').value;
if(lastCategory) {
categories.openTo(lastCategory, true);
}


I knew it'd be something simple like that

Hope this helps someone else!

-Robur

P.S. See it in action at safarri.com ! (Notice the "Ad Categories" box on the right)

« BackwardsOnwards »

Show Forum Drop Down Menu