• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Passing IFRAME Parameters via Web Link

I need a little help on how to pass paramenters to an IFRAME via a link.

I have a page called minutes.htm that has a dynamic menu bar at the top of the page and the bottom part is an IFRAME where the selected contents show. The default document that displays in the IFRAME is blank.htm.

From my index.htm page I want to create a link that will open up minutes.htm and also pass along a parameter so that I can specify a different document to open up in the IFRAME.
0
doby48
Asked:
doby48
  • 4
  • 4
  • 3
  • +2
1 Solution
 
gamebitsCommented:
There is a javascript code snipet to open to different pages with one link but it target 2 frames, you might want to look at it see if you can adapt it to your needs.

http://javascript.internet.com/navigation/load-two-frames.html

Gamebits
0
 
jessegivyCommented:
so, lemme get this straight (a little confused), you're opening minutes.htm in an iFrame which lives on the index.htm page?  The link should look something like this if that's the case, otherwise please try to explain further.  Lets say your iFrame is the only one on the page:

<a href="#" onClick="document.frames[0].location="minutes.htm?param1=value1&param2=value2">Minutes</a>

notice the parameters I've sent using a querystring?  Everything after the question mark is a list of parameters delimited by the ampersand '&' character, they're name value pairs that can be retrieved using the request object...

...hmmm, I just realized that your pages have a .htm extension so you probly won't have a request object handy...

...If you wanna fake it, you could just set the value of a hidden field in minutes.htm like this:

<a href="#" onClick="document.frames[0].location='minutes.htm';document.getElementById('hiddenID').value='paramValue'">Minutes</a>

...to accomplish something like this you'll have to make sure there's a hidden field located on the minutes.htm file that you can create like this

<input type="hidden" id="hiddenID">

Geez that was a longwinded answer, sure there's at least a coupla nuggets in there for ya.

Cheers,

JGI
0
 
jessegivyCommented:
Oh my, change this:

<a href="#" onClick="document.frames[0].location='minutes.htm';document.getElementById('hiddenID').value='paramValue'">Minutes</a>

To this:

<a href="#" onClick="document.frames[0].location='minutes.htm';document.frames[0].document.getElementById('hiddenID').value='paramValue'">Minutes</a>

...the old version would access a hidden field with an id of "hiddenID" that is located on the index.htm page.  Sorry about the confusion.

Best of luck
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
doby48Author Commented:
Actually I have a page called minutes.htm that has an IFRAME at the bottom of the page. By default when minutes.htm loads the IFRAME content is 1970.htm. What I want to do is to place a link on my index.htm page that will call the minutes.htm but load the page 1980.htm in the IFRAME (instead of the default 1970.htm). This link will be updated on a regular basis and I just need to somehow pass the paramaters of the link so that a different page other than default loads into the IFRAME of minutes.htm. Make sense?
0
 
mail4kajaCommented:
Use "On-Change" Event to trigger the function that process which item has been selected, then use IFRAME id.href to redirect to another required page.

Hope this works for your need.
0
 
gamebitsCommented:
The way I understand the question is on the page index.html you want a link to open minute.html that is easy enough just a regular link so far, where it is getting complicated is you also want that link to open another page within a iframe so basically 1 link -> 2 destinations.

That's what the link I gave you above does but the 2 destinations are frames, not sur if it can be done with a regular page holding a Iframe.

Gamebits
0
 
SammoCommented:
Hi there,

Had a bit of a play around and came up with this:

<body onload="changeIFrame(); return false;">
<script language="javascript">

function changeIFrame()
{
      var sURL = window.document.URL.toString();
      
      if (sURL.indexOf("?") > 0)
      {
            var arrParams = sURL.split("?");
                  
            var arrURLParams = arrParams[1].split("&");
            
            var arrParamNames = new Array(arrURLParams.length);
            var arrParamValues = new Array(arrURLParams.length);
            
            var i = 0;
            for (i=0;i<arrURLParams.length;i++)
            {
                  var sParam =  arrURLParams[i].split("=");
                  arrParamNames[i] = sParam[0];
                  if (sParam[1] != "")
                        arrParamValues[i] = unescape(sParam[1]);
                  else
                        arrParamValues[i] = "No Value";
            }
      }

      


      frames['iframename'].location.href = arrParamValues[0];

}


</script>

<iframe src="about:blank"
      name="iframename" ></iframe>


Put this in the page with the iframe on. (minute.html)

You can then link to minute.html like this:

<a href="minute.html?anywordhere=1970.htm">1970</a>
<a href="minute.html?anywordhere=1980.htm">1980</a>

This works for me in firefox if you have any problems get back to me.

Hope this helps.

Sam
0
 
jessegivyCommented:
So, minutes.htm is NOT being loaded into an iFrame???  If so, that's a little tough, if minutes.htm is actually being loaded into an iFrame then you can change the default iFrame on minutes.htm like this:

<a href="#" onClick="document.frames[0].location='minutes.htm';document.frames[0].document.frames[0].src='1980.htm'">Minutes</a>

...no, this doesn't really make sense to me, is the "parameter passing" required because it will be changed dynamically, if so how will this happen.  It sounds like some static pages, and you can just change the default page specified for the iFrame on minutes.htm if so???  ...The hidden field idea will work, you'll just have to specify it as the src of the iFrame onload of minutes.htm, but could skip the step by using above link
0
 
doby48Author Commented:
<b>jessegivy</b>
Not sure what the problem is but I am getting errors when using what you provided, I am getting the error of:
'document.frames.0' is null or not an object.

<b>Sammo</b>
When I use your script I get errors as well.

I have been able to get close though with another script. The script works with IE, NS and FF but does not work with Opera. When this script is used in Opera then it loads minutes.htm within minutes.htm. within minutes.htm within minutes.htm (loads the minutes.htm page and loads itself into the iframe and within that iframe loads itself again,etc.) Here is what has gotten me close:

On the index.htm page I used the following link:
<a href="minutes.htm?i=minutes/1980.htm">Minutes</a>

On the minutes.htm page I used the following in <head>
<script type="text/javascript">

window.onload = function setIframe() {

        var url = window.location.href;
        var i = url.indexOf("?i=");
        if( i>-1 ) {
                url = url.substr(i+3);
                document.getElementById("MeetingDetails").src = url;
        }
}
</script>

Any thoughts on suggestions? I am still open to doing this with any method that I can get to work.
0
 
SammoCommented:
Hmm weird, I got no errors on that code that I wrote for you before.

Try changing your <script> code to:

<script language="javascript">


window.onload = function changeIFrame()
{
     var sURL = window.document.URL.toString();
     
     if (sURL.indexOf("?") > 0)
     {
        i = sURL.indexOf("?");
      sURL = sURL.substr(i+3);
     }


     frames['MeetingDetails'].location.href = sURL;

}
</script>



Where the iframe has:
name="MeetingDetails"


Hope this helps

Sam.
0
 
doby48Author Commented:
Same results as the previous Javascript, looks to be incompatible with Opera loading the meeting.htm within the iframe of meeting even when not following a link to that page. Any suggestions?
0
 
SammoCommented:
Yeah I just installed opera and it just loads the page over and over inside the iframe.

I changed the code to this and it seems to work perfectly in Opera 8.54 and Firefox 1.5.0.2:

<script language="javascript">


window.onload = function changeIFrame()
{
     var sURL = window.document.URL.toString();
     
     if (sURL.indexOf("?") > 0)
     {
        i = sURL.indexOf("?");
      sURL = sURL.substr(i+3);
        frames['MeetingDetails'].location.href = sURL;
     }

}


</script>

Hope this sorts it!

0
 
doby48Author Commented:
Thank you Sammo that works perfect. I really appreciate your help with this issue.
0
 
SammoCommented:
No problem, glad I could help!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now