iframe src variables

Discussion in 'Javascript' started by mkhines, May 29, 2008.

  1. mkhines

    mkhines Guest

    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/ecoregions/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/ecoregions/bigpage.html?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!!!!
     
    mkhines, May 29, 2008
    #1
    1. Advertising

  2. 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
    --
     
    Álvaro G. Vicario, May 29, 2008
    #2
    1. Advertising

  3. mkhines

    mkhines Guest

    On May 29, 4:32 am, "Álvaro G. Vicario"
    <> wrote:
    > 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
     
    mkhines, May 29, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Richter

    <txt src= ...> equivalent of <img src= ...>

    Steve Richter, Feb 8, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    2,109
    Laurent Bugnion
    Feb 9, 2006
  2. Greg Johnson
    Replies:
    4
    Views:
    3,090
  3. Replies:
    1
    Views:
    1,628
    Alex Hunsley
    Mar 23, 2007
  4. pheadxdll
    Replies:
    16
    Views:
    3,700
    Neredbojias
    Jun 6, 2007
  5. Soren Vejrum
    Replies:
    4
    Views:
    630
    Lasse Reichstein Nielsen
    Jul 5, 2003
Loading...

Share This Page