homepage Welcome to WebmasterWorld Guest from 54.197.111.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript to load page in frame generates the wrong URI
needs correct page name and variables to get products
balpal




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

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:

<html>
<head>
<title><title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
<!--
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 + "')";
eval(s);
}
return;
}
//-->
</script>
</head>
<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>
</frameset></frameset>
<noframes>
<body bgcolor="#FFFFFF" text="#000000">
No Frames! Please call xxx
</body>
</noframes>
</html>

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

<SCRIPT LANGUAGE="JavaScript">
<!-- FRAME CHECK START
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;
top.location.replace(s);
}
return;
}
frameMe();
// --> FRAME CHECK END
</SCRIPT>

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.

Cheers.

 

jeremy goodrich




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

Hm, not sure on all this.

Anybody else?

ShawnR




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

Hi

Say your original url was:

item.asp?designer=Cartier&brand=Declaration&sex=M

In frameMe, you create the following

index.html?item.asp?designer=Cartier&brand=Declaration&sex=M&main

(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
index.html?item.asp%3fdesigner%3dCartier%26brand%3dDeclaration%26sex%3dM&main

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

Shawn

balpal




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


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?

Cheers

A.

ShawnR




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

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.

Shawn

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];

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved