Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing source of an iFrame according to URL variable.

Status
Not open for further replies.

craigsman

Programmer
Oct 27, 2004
15
AU
Hey all.

NB.I'm a begginer at Javascript so please try and explain everything. Thanks.

I would really apreciate it if someone could help me cange the source of an iFrame depending on a var. in the URL.

Heres my code...
Code:
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
  <html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">
  <head>
  	<title>Scab Auctions - Home</title>
      <link rel="stylesheet" type="text/css" href="externalcss.css" />

  </head>

  <body>
  <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
 codebase="[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"[/URL]
 WIDTH="100%" HEIGHT="236" id="top" ALIGN="">
   <PARAM NAME=movie VALUE="dowtop2.swf"> <PARAM NAME=quality   VALUE=high> <PARAM NAME=bgcolor VALUE=#000000> <EMBED src="dowtop2.swf" quality=high bgcolor=#000000  WIDTH="100%" HEIGHT="236" NAME="top" ALIGN=""
  TYPE="application/x-shockwave-flash" PLUGINSPAGE="[URL unfurl="true"]http://www.macromedia.com/go/getflashplayer"></EMBED>[/URL]

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


    <iframe src="home.html" name="content" width="100%" height="350" scrolling="auto" frameborder="0">
      [Your user agent does not support frames or is currently configured
    not to display frames. 
    </iframe>


      </td>
      </tr>
    </table>
  </body>
  </html>

A sample:
If the URL is... blah.com?q=login

Then the iFrame src. will be login.html

and so on.

Thanks in advance, I'm not sure if i explained myself properly.
 
have you tried something like :

document.content.location='login.html';

This should take you to the login page. all you will then need to do is to process the QueryString for the values you want.
 
It didnt seem to work. whatever i set the src to in the iFrame tags is what it is. and if i leave them blank, the iframe is blank. i tried changing .location into .src but same result.

btw i have no idea how to process the query string.
 
Here's an example.

Code:
<script type="text/javascript">

function getQueryStringVars() {
  
	var server_variables = {};
	var query_string = window.location.search.split( "?" )[ 1 ];
	if ( ! query_string ) return false; 
	var get = query_string.split( "&" );

	for ( var i=0; i < get.length; i++ ) {

		var pair = get[ i ].split( "=" );
		server_variables[ pair[ 0 ] ] = unescape( pair[ 1 ] );
	}

	return server_variables;
}

window.onload = function() {

	ifr = document.getElementsByTagName( "iframe" )[ 0 ];
	args = getQueryStringVars();

	if ( args[ "q" ] == "google" ) ifr.src = "[URL unfurl="true"]http://www.google.com";[/URL]
	if ( args[ "q" ] == "jeeves" ) ifr.src = "[URL unfurl="true"]http://www.ask.com";[/URL]
}

</script>

<a href="iframeSrcChange.html?q=google">google</a>
<a href="iframeSrcChange.html?q=jeeves">jeeves</a>
<iframe src=""></iframe>

See if you can adapt it to what you need.
 
Your a ledgend theboyhope
Thanks Heeps
Worked perfectly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top