PDA

View Full Version : URL not passing correctly to page with iframe



webworxplus
10-09-2008, 04:20 PM
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


<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


<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

jscheuer1
10-09-2008, 06:12 PM
You need to encode the URI component:

models.htm


<a href="modellist.htm?framepage=http%3A%2F%2Fdealers.autouplinkusa.com%2Fv%2F%3FDealerId%3D6083%26LocationId%3D001%26object%3Dlist%26MAKE%3DFord%26MODEL%3DFocus%26maxro ws%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:


<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.

webworxplus
10-09-2008, 08:50 PM
Thank you John...added the decodedURI and it worked perfectly...