Solved

Pass parameters in URL to dynamically build the src for an iFrame on another page

Posted on 2004-09-30
4
610 Views
Last Modified: 2010-04-06
Started off in the HTML section, but think I've narrowed this down with some help.

I would like to be able pass parameters via a URL and have them picked up on the target page (could be a link or created from a form). This target page would have an IFRAME whose src I need to update with a URL I construct based on the parameters passed in the URL.

Everything must be done in the client since my hosting platform does not support any server side scripting. Also, it needs to be in javascript and all I know is vbscript. I'm not strong in web scripting.

I think what I need to know is how to capture the parameters I pass, and then how to change the src of the IFRAME. A simple example will likely suffice, but I can provide more detail if needed.

Thanks,

MikeB
0
Comment
Question by:mboysen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 12193012
<script type="text/javascript">
function iframe_goto(new_url)
{
  document.getElementById('myiframe').src=new_url;
}

function somefunction(value1, value2)
{
 iframe_goto('http://www.myscript.com/somepage.html?value1=' + value1 + '&value2=' + value2);
}
</script>
<iframe id="myiframe" src=""></iframe>

<button onclick="somefunction(1,2)">Click me</button>

0
 
LVL 18

Accepted Solution

by:
arantius earned 100 total points
ID: 12193039
var qs = location.search.substring(1).split("&");
var Querystring = new Array()
for(i=0;i<qs.length;i++) {
    t = qs[i].split("=")
    if(t[0] && t[1]) Querystring[t[0]] = unescape(t[1]);
}

This code (javascript) should create an array called Querystring based off of the querystring in the URL.  This is the stuff after the file: ?name=value&othername=othervalue .

Place the appropriate name/value pairs into the URL.  THen after running that javascript, use something like this:

document.getElementById("theIframe").src="http://"+Querystring["domain"]+"/"+Querystring["page"];
0
 

Author Comment

by:mboysen
ID: 12193468
This is exactly what I was looking for.

MikeB
0
 

Author Comment

by:mboysen
ID: 12194060
OK. Here's the final solution. Thanks for the help

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body onLoad="updateFrame()" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">

<script type="text/javascript">
      var qs = location.search.substring(1).split("&");
      var QueryString = new Array()
      for(i=0;i<qs.length;i++) {
            t=qs[i].split("=")
            if(t[0] && t[1]) QueryString[t[0]] = unescape(t[1]);
            }
      var qURL = "http://www.orderhomeplans.com/widgets/planstyle.asp?hspos=E42NET&style="+QueryString["style"];
      
      function updateFrame()
      {
            frameID = "isearch1";
            //document.all[frameID].src = qURL;
            document.getElementById(frameID).src=qURL;
      }
            
</script>


<div align="center">

<table border="0" cellpadding="0" cellspacing="0" width="725" height="100%">
      <!-- MSTableType="layout" -->
      <tr>
            <td valign="top" colspan="2" height="90">
            <!-- MSCellType="DecArea" -->
            <table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
      <!-- MSCellFormattingTableID="1" -->
      <tr>
            <td bgcolor="#000000" nowrap height="20">
            <!-- MSCellFormattingType="header" -->
            &nbsp;</td>
      </tr>
      <tr>
            <td valign="top" bgcolor="#00FFFF" height="100%" width="100%">
            <!-- MSCellFormattingType="content" -->
            Test</td>
      </tr>
            </table>
      </td>
      </tr>
      <tr>
            <td valign="top" width="132" height="571">
            <!-- MSCellType="NavBody" -->
            <table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
      <!-- MSCellFormattingTableID="2" -->
      <tr>
            <td valign="top" bgcolor="#FF0000" height="100%">
            <!-- MSCellFormattingType="content" -->
            Test</td>
      </tr>
      <tr>
            <td nowrap bgcolor="#000000" height="20" width="100%">
            <!-- MSCellFormattingType="footer" -->
            &nbsp;</td>
      </tr>
            </table>
            </td>
            <td valign="top" height="571" width="694">
            <!-- MSCellType="ContentBody" -->                  

      
            <iframe name="isearch" id="isearch1" src="" marginwidth="1" marginheight="1" height="100%" width="100%">
            Your browser does not support inline frames or is currently configured not to display inline frames.
            </iframe>            
      

      
</td>
      </tr>
</table>

</div>

</body>

</html>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question