Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Javascript to load page in frame generates the wrong URI

needs correct page name and variables to get products



4:41 pm on May 16, 2003 (gmt 0)

5+ Year Member

I have an 'item.asp' page which, when you add variables after it, it will return the wanted product eg 'item.asp?designer=Cartier&brand=Declaration&sex=M'.

The site works in frames (framer page is index.html) and I need to load up the top and bottom frames of the site if a user just goes to www.anything.com/item.asp. I have the javascript in place to do this but when you add the needed variables after item.asp it doesn't bring back any products. I know why this is, its because the URL after the frame redirection is 'www.anything.com/index.html?item.asp', and should be 'www.anything.com/item.asp'. Is there anyway to hide the index.html? that is shown before the item.asp in the browser URL so that it is just 'www.anything.com/item.asp?'?

On the 'index.html' page my code is:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
function loadDoc(){
var a = location.search.split('&');
var page = a[0].substr(1);
var frame = a[1];
if(page && frame){
var s = "top." + frame + ".location.replace('" + page + "')";
<frameset rows="130,*">
<frame src="indexheader.htm" name="header" id="header" frameborder="0" scrolling="No" noresize>
<frameset cols="170,580" onLoad="loadDoc()">
<frame src="sideframe.asp" name="right" id="right" frameborder="0" scrolling="No" noresize>
<frame src="item.asp" name="main" id="main" frameborder="0" scrolling="No" noresize>
<body bgcolor="#FFFFFF" text="#000000">
No Frames! Please call xxx

On the 'item.asp' page my coding is:

function frameMe(){
var frameset = "index.html"; //name of the frameset page
var frame = "main"; //name of the frame to load document into
page = new String(self.document.location);
var pos = page.lastIndexOf("/") + 1;
var file = page.substr(pos);
if(window.name!= frame){
var s = frameset + "?" + file + "&" + frame;

Otherwise does anyone have some code from a similar project I could use?

I surely can't be the only person trying to do this? And please no jokes about "well the best way is to not use frames" as I know this, I did not code the site originally.


jeremy goodrich

3:22 am on May 19, 2003 (gmt 0)

WebmasterWorld Senior Member jeremy_goodrich is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Hm, not sure on all this.

Anybody else?


3:38 pm on May 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


Say your original url was:


In frameMe, you create the following


(I think. Check by doing an alert)

That is not great because it contains two '?' characters.

Then in loadDoc you split on '&', so you can see what sort of mess you will get into.

I suggest you 'escape' (e.g. convert to hex codes) the '?', '=', and '&' symbols in the original url as a first step in FrameMe, so that you create something like

Then in loadDoc, 'unescape' a[0].



10:16 am on May 20, 2003 (gmt 0)

5+ Year Member

Hi ShawnR,

Many thanks for your suggestion, unfortunately my Javasript isn't brilliant and this is the first time I have tried to convert the necessary characters to Hexcode. Would you be able to show me where in the coding I need to make the necessary changes?




11:18 am on May 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Try this:

In function frameMe():
var file = page.substr(pos);
file = escape(file);
if(window.name!= frame){

In function loadDoc():
var page = a[0].substr(1);
page = unescape(page);
var frame = a[1];

Haven't tested it, but I think it should work.


PS Equivalent, but slightly neater:

In function frameMe():
var file = escape(page.substr(pos));
if(window.name!= frame){

In function loadDoc():
var page = unescape(a[0].substr(1));
var frame = a[1];


Featured Threads

Hot Threads This Week

Hot Threads This Month