iframe src variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mkhines

    iframe src variables

    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


    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


    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.searc h.substring(9);
    alert(zipcode2) ;
    </script>
    <iframe frameborder="0" height="100%" width="100%"
    src="http://wildlifedisease .nbii.gov/ecoregions/index.jsp?zipco de=
    +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!!!!
  • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

    #2
    Re: iframe src variables

    mkhines escribió:
    <html>
    <body>
    <script type="text/javascript">
    var zipcode2=window .location.searc h.substring(9);
    alert(zipcode2) ;
    </script>
    <iframe frameborder="0" height="100%" width="100%"
    src="http://wildlifedisease .nbii.gov/ecoregions/index.jsp?zipco de=
    +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.searc h.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?zipco de=' +
    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
    --

    Comment

    • mkhines

      #3
      Re: iframe src variables

      On May 29, 4:32 am, "Álvaro G. Vicario"
      <alvaroNOSPAMTH A...@demogracia .comwrote:
      mkhines escribió:
      >
      <html>
      <body>
      <script type="text/javascript">
      var zipcode2=window .location.searc h.substring(9);
      alert(zipcode2) ;
      </script>
      <iframe frameborder="0" height="100%" width="100%"
      src="http://wildlifedisease .nbii.gov/ecoregions/index.jsp?zipco de=
      +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.searc h.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?zipco de='+
      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.substri ng(9);
      var url = "http://wildlifedisease .nbii.gov/ecoregions/
      index.jsp?zipco de=" + zipcode2;
      document.getEle mentById("myfra me").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

      Comment

      Working...