Connecting Tech Pros Worldwide Forums | Help | Site Map

Call to page and load IFRAME

Newbie
 
Join Date: Oct 2006
Posts: 2
#1: Oct 27 '06
How would I encode a URL on home.htm to open another page (index1.htm) which contains an Iframe with name="test" and id="test" and load it with include1.htm or include2.htm which resides in the same directory as index1.htm.

------------------------
Example: (button 1 needs encoding)

home.htm -> button 1 -> links to index1.htm

Index1.htm -> iframe name and id="test"

iframe "test" -> displays one of two includes as defined by button 1 encoding

Newbie
 
Join Date: Oct 2006
Posts: 2
#2: Oct 27 '06

re: Call to page and load IFRAME


How would I encode a URL on home.htm to open another page (index1.htm) which contains an Iframe with name="test" and id="test" and load it with include1.htm or include2.htm (load variables by url or javascript) which resides in the same directory as index1.htm.

------------------------
Example: (button 1 needs encoding)

home.htm -> button 1 -> links to index1.htm

Index1.htm -> iframe name and id="test"

iframe "test" -> displays one of two includes as defined by button 1 encoding
Newbie
 
Join Date: Nov 2006
Location: Minneapolis
Posts: 1
#3: Nov 17 '06

re: Call to page and load IFRAME


Quote:

Originally Posted by Dennis Sirois

How would I encode a URL on home.htm to open another page (index1.htm) which contains an Iframe with name="test" and id="test" and load it with include1.htm or include2.htm which resides in the same directory as index1.htm.
------------------------
Example: (button 1 needs encoding)
home.htm -> button 1 -> links to index1.htm
Index1.htm -> iframe name and id="test"
iframe "test" -> displays one of two includes as defined by button 1 encoding

You can do this easily with a querystring that passes the URL to load as follows:

First, add JavaScript to the header of index1.htm:
(note that test is the name/id of your iframe element)

<script type="text/javascript">
function loadIframe()
{
var urlStr;
urlStr = location.search.slice(1);
window.frames.test.location = urlStr;
}
</script>

Next, call the function in the body onload:

<body onLoad="loadIframe()">

Then, in the home page, make links that use a querystring to pass the info:

<a href="index1.htm?page1.htm">Page 1</a>
<a href="index1.htm?page2.htm">Page 2</a>

Now, the links go to the page with the iframe, the function parses out the page passed by the query string, and sets the src of the text iframe with it. You can just have src="" on the page, as it's going to get reset anyway.

-Skarjune
Reply


Similar JavaScript / Ajax / DHTML bytes