Results 1 to 3 of 3

Thread: URL not passing correctly to page with iframe

  1. #1
    Join Date
    Sep 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default URL not passing correctly to page with iframe

    Good afternoon...

    I am relatively new to working with javascript and am in need of some help with a problem I'm having. Here's what I'm trying to accomplish:

    I have a page called modellist.htm with an iframe set up on it; I have a second page called models.htm with a link on it that when clicked opens modellist.htm with a specific url in the iframe that was passed from the link on models.htm. What's happening is that the link is not passing correctly and what I'm not sure of is if there is a limitation on the length of the url that can be passed..

    Here's the code I've used:

    modellist.htm

    Code:
    <script type="text/javascript">
    function loadframe(){
    if(window.location.replace)
    window.frames.ModelFrame.location.replace(get('framepage'));
    else
    window.frames.ModelFrame.location.href=get('framepage');
    }
    function get(key_str) {
    var query = window.location.search.substr(1);
    var pairs = query.split("&");
    for(var i = 0; i < pairs.length; i++) {
    var pair = pairs[i].split("=");
    if(unescape(pair[0]) == key_str)
    return unescape(pair[1]);
    }
    return null;
    }
    if (location.search&&get('framepage')!=null)
    if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", loadframe, false );
    else if ( typeof window.attachEvent != "undefined" )
    window.attachEvent( "onload", loadframe );
    else {
    if ( window.onload != null ) {
    var oldOnload = window.onload;
    window.onload = function ( e ) {
    oldOnload( e );
    loadframe();
    };
    }
    else
    window.onload = loadframe;
    }
    </script>
    </head>
    
    <body>
    <iframe name="ModelFrame" src="" width="800" height="800" frameborder="1"></iframe>
    models.htm

    Code:
    <a href="modellist.htm?framepage=http://dealers.autouplinkusa.com/v/?DealerId=6083&LocationId=001&object=list&MAKE=Ford&MODEL=Focus&maxrows=24&MinYear=&MaxYear=2009&Type=N&MinPrice=&MaxPrice=&STYLE=&ExtColor=&MaxMiles=&StockNo=">Click Here</a>
    Like I mentioned, I am new to this and maybe there is a better way to handle this so I am open to any and all suggestions. Thank you in advance for the help.

    Mark
    Last edited by jscheuer1; 10-09-2008 at 05:57 PM. Reason: format code

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You need to encode the URI component:

    models.htm

    Code:
    <a href="modellist.htm?framepage=http%3A%2F%2Fdealers.autouplinkusa.com%2Fv%2F%3FDealerId%3D6083%26LocationId%3D001%26object%3Dlist%26MAKE%3DFord%26MODEL%3DFocus%26maxrows%3D24%26MinYear%3D%26MaxYear%3D2009%26Type%3DN%26MinPrice%3D%26MaxPrice%3D%26STYLE%3D%26ExtColor%3D%26MaxMiles%3D%26StockNo%3D">Click Here</a>
    It can be difficult to determine how to do this with any given URL that you want to pass to the other page. I just made up a script:

    Code:
    <script type="text/javascript">
    document.write(encodeURIComponent('http://dealers.autouplinkusa.com/v/?DealerId=6083&LocationId=001&object=list&MAKE=Ford&MODEL=Focus&maxrows=24&MinYear=&MaxYear=2009&Type=N&MinPrice=&MaxPrice=&STYLE=&ExtColor=&MaxMiles=&StockNo='))
    </script>
    Then viewed that in the browser and copied and pasted it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    webworxplus (10-09-2008)

  4. #3
    Join Date
    Sep 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default I new it would be something easy...

    Thank you John...added the decodedURI and it worked perfectly...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •