469,610 Members | 1,554 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

Using a variable in the src attribute of iframe

Hi everyone,

I've finally figured out what I actually want to do with my website, let's
hope this time I can explain it better.

The opening page of the website has a bunch of links that look somewhat
like:

<a href="geninfo.html?sub_contact.html">

The page geninfo.html contains an inline frame called "frame" and has a
short script like this:

<!--
var temp=window.location.split("?");
var content=temp[1]
//-->

I am assuming after I clicked the link from the opening page the variable
"content" now contains "sub_contact.html". Am I correct?

How can I use this variable in my iframe tag?

I've tried this:

<iframe name="frame" height="409" width="580" border="0" frameborder="0"
src=content scrolling="no">

but that's obviously wrong since it didn't work.

Can someone please tell me how I can achieve this? I'm very new in web
scripting/programming.

Thanks for the answers so far and any further suggestions would be greatly
appreciated.

Cheers,
Dany.
Jul 20 '05 #1
1 7362
Dany P. Wu wrote on 17 Nov 2003:
Hi everyone,

I've finally figured out what I actually want to do with my
website, let's hope this time I can explain it better.

The opening page of the website has a bunch of links that look
somewhat like:

<a href="geninfo.html?sub_contact.html">

The page geninfo.html contains an inline frame called "frame"
and has a short script like this:

<!--
var temp=window.location.split("?");
var content=temp[1]
//-->

I am assuming after I clicked the link from the opening page the
variable "content" now contains "sub_contact.html". Am I
correct?

How can I use this variable in my iframe tag?

I've tried this:

<iframe name="frame" height="409" width="580" border="0"
frameborder="0" src=content scrolling="no">

but that's obviously wrong since it didn't work.

Can someone please tell me how I can achieve this? I'm very new
in web scripting/programming.

Thanks for the answers so far and any further suggestions would
be greatly appreciated.


If you aren't going to add any other parameters to the URL (ever),
then you could simply do:

var content = window.location.search.substr( 1 );

The substr( 1 ) call simply strips the question mark from the search
property, which returns everything from the question mark onwards in
a URL.

However, if you do plan on adding other parameters, then it would be
better to do something like:

// Create an array of parameters passed to the page
// Ampersands (&) should be used to separate name/value pairs
var parameters = window.location.search.substr( 1 ).split( '&' );
var content = parameters[0];

Hope that helps,
Mike

--
Michael Winter
M.Winter@[no-spam]blueyonder.co.uk (remove [no-spam] to reply)
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Torsten Reiners | last post: by
2 posts views Thread by Linus Martinsson | last post: by
4 posts views Thread by tfortney | last post: by
14 posts views Thread by Dario de Judicibus | last post: by
3 posts views Thread by Senthil | last post: by
1 post views Thread by RuthC | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.