By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,517 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,517 IT Pros & Developers. It's quick & easy.

iframe src variables

P: n/a
I'm having trouble figuring out the proper way to pass this variable
in with javascript alone. I'm not used to not being able to use jsp
and all the love that is in that.

Obviously I know little about javascript!

So you get the whole story, the user will begin on a page which has an
iframe in it that picks up a parameter
http://wildlifedisease.nbii.gov/ecor...theirpage.html

which contains an iframe that passes a parameter when the form is
submitted to ANOTHER page with an iframe which needs to pick up that
parameter.

So, for example, if you put in 11211 in the text box on the first
page, and submit it, it opens a new window and pushes over the zipcode
parameter value to that next page
http://wildlifedisease.nbii.gov/ecor...?zipcode=11211

what i need to do now, is get the iframe in bigpage.html to pick up
that zipcode parameter.

i'm using a substring function (here's the code for bigpage.html) to
get the zipcode value

<html>
<body>
<script type="text/javascript">
var zipcode2=window.location.search.substring(9);
alert(zipcode2);
</script>
<iframe frameborder="0" height="100%" width="100%"
src="http://wildlifedisease.nbii.gov/ecoregions/index.jsp?zipcode=
+zipcode2.value+"></iframe>
</body>
</html>

which works fine, but I can't figure out how to properly write the
src="" part.. i've tried every combination of apostrophes and plus
signs, argh!

help?

Thanks!!!!
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
mkhines escribió:
<html>
<body>
<script type="text/javascript">
var zipcode2=window.location.search.substring(9);
alert(zipcode2);
</script>
<iframe frameborder="0" height="100%" width="100%"
src="http://wildlifedisease.nbii.gov/ecoregions/index.jsp?zipcode=
+zipcode2.value+"></iframe>
</body>
</html>
You can't just insert JavaScript code anywhere in your HTML. If you
write "zipcode2.value", how can the browser know it's not HTML?

You probably want something like this, but please make sure you
understand why your code did not work and you'll prevent lots of headaches.

<script type="text/javascript"><!--
var zipcode2=window.location.search.substring(9);
// This is only one line, it was wrapped by my newsreader:
document.write('<iframe frameborder="0" height="100%" width="100%"
src="http://wildlifedisease.nbii.gov/ecoregions/index.jsp?zipcode=' +
escape(zipcode2.value) + '"><\/iframe>');
//--></script>

Code is not tested.

Be aware that your iframe won't event exist for non JS aware user agents.

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 27 '08 #2

P: n/a
On May 29, 4:32 am, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
mkhines escribió:
<html>
<body>
<script type="text/javascript">
var zipcode2=window.location.search.substring(9);
alert(zipcode2);
</script>
<iframe frameborder="0" height="100%" width="100%"
src="http://wildlifedisease.nbii.gov/ecoregions/index.jsp?zipcode=
+zipcode2.value+"></iframe>
</body>
</html>

You can't just insert JavaScript code anywhere in your HTML. If you
write "zipcode2.value", how can the browser know it's not HTML?

You probably want something like this, but please make sure you
understand why your code did not work and you'll prevent lots of headaches..

<script type="text/javascript"><!--
var zipcode2=window.location.search.substring(9);
// This is only one line, it was wrapped by my newsreader:
document.write('<iframe frameborder="0" height="100%" width="100%"
src="http://wildlifedisease.nbii.gov/ecoregions/index.jsp?zipcode='+
escape(zipcode2.value) + '"><\/iframe>');
//--></script>

Code is not tested.

Be aware that your iframe won't event exist for non JS aware user agents.

--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
Thanks, I eventually did this based on another recommendation. I do
see that as a problem, but if I need to pass variables to an iframe on
a different group's server, i'm not sure there is any other way for me
to do what i'm trying to do.. we need to host the application on a
server that can run tomcat/database etc. and they don't have that
ability.

(here is the code i went with in the end)
<html>
<script type="text/javascript">
function init() {
var zipcode2 = window.location.search.substring(9);
var url = "http://wildlifedisease.nbii.gov/ecoregions/
index.jsp?zipcode=" + zipcode2;
document.getElementById("myframe").src = url;
}
</script>
<body onLoad="init()">
<iframe id="myframe" frameborder="0" height="100%" width="100%"
src=""></iframe>
</body>
</html>

is there some other way to pass those variables to the iframe without
javascript?

thanks!

megan
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.