Forum Moderators: open
My client has a website which is still using framesets - (I like to think of it as a 'vintage' site) - what's more, a complex assortment of javascripts make sure that if you try to load a page on it's own, it loads itself inside of it's appropriate frameset.
This is all fine.
But I've just built a latest news CMS for this site (before all news was updated manually in the html) - It works great - except one problem
www.example.com/newsitem.asp?newsID=25 - would be a link (for example) to take you to a specific news item.. of course.. the javascript says "hey! that's not in the frameset - and promptly puts it in the frameset, but STRIPS the all important ?newsID=25 bit off the end - so you get the main news page, not the individual item
We need the individual item.. and I'm not good enough at javascript to do that.
Here's the script that does the dirty deed:
function loadMeInFrame()
{
detectBrowser();
var strPathBreak = '/';
var strPath = location.pathname;
if ((location.protocol == 'file:') && (browserIE4))
strPath = strPath.replace(/\x5c/g, strPathBreak);
var strPage = strPath.substring(strPath.lastIndexOf(strPathBreak) + 1);
if (top == self)
self.location.replace('index.htm?p=' + strPage);
}
and also there's some other code lurking about in this old and spaghetti coded site that looks like this
// Get URL parameters
function GetURLParams()
{
var strCallingURL = new String(parent.document.location);
var strParams = strCallingURL.substring(strCallingURL.indexOf('?'), strCallingURL.length);
return(strParams);
}
// Parse variables passed on URL line
// Assumes global variable strURLParams
function ParseURLVars(strURLParams, strName)
{
var DELIMETER = '&'; // STANDARD CGI CALLING PARAMETER SEPARATOR/DELIMETER
var partialString = '';
if (strURLParams.indexOf(strName + '=') != -1)
{
partialString = strURLParams.substring(strURLParams.indexOf(strName + '=') + strName.length + 1, strURLParams.length); // ENSURE THAT AN ENDING DELIMETER EXISTS
if (partialString.indexOf(DELIMETER) != -1)
{
return(partialString.substring(0, partialString.indexOf(DELIMETER)));
}
else
{
// NO DELIMETER EXISTS, COPY TO END OF STRING
return(partialString);
}
}
else
{
return('');
}
}
// Make default frame set
function MakeDefaultFS(document)
{
var strURLParams = GetURLParams();
var strPage = ParseURLVars(strURLParams, 'p');
if (strPage == '') strPage = 'main.asp';
var strBkm = ParseURLVars(strURLParams, 'b');
if (strBkm != '') strBkm = '#' + strBkm;
document.writeln('<frameset framespacing="0" border="0" frameborder="0" rows="100,27,*">');
document.writeln(' <frame name="banner" scrolling="no" noresize target="main" src="../banner/banner.htm" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" noresize>');
document.writeln(' <frame name="menu" scrolling="no" noresize target="main" src="../menus/menu.htm" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" noresize>');
document.writeln(' <frameset framespacing="0" border="0" frameborder="0" cols="160,*">');
document.writeln(' <frame name="toc" target="main" src="toc.asp" frameborder="0" marginwidth="5" marginheight="1" scrolling="auto" noresize>');
document.writeln(' <frame name="main" src="'+strPage+strBkm+'" frameborder="0" marginwidth="10" marginheight="10" scrolling="auto" noresize>');
document.writeln(' </frameset>');
document.writeln('</frameset>');
document.writeln('<noframes>');
document.writeln('<body topmargin="0" leftmargin="0">');
document.writeln('<p>This page uses frames, but your browser does not support them.</p>');
document.writeln('</body>');
document.writeln('</noframes>');
}
Now.. the individual page I want - usually calls the first bit of code I posted.. and the index.htm page - that get's loaded - then builds the frameset with the second bit of code
Can anybody help? what do I need to juggle about so that the site doesn't turn this: www.example.com/newsitem?newsID=25
into this:
http://www.example.com/index.htm?p=news_item.asp
all responses greatly appreciated!
-s42
here's the solution I found
basically.. I stopped trying to make the new news pages use the standard frameset making Javascript.
in the actual potentially orphaned page I put this at the top:
<%strNewsID = Request.querystring("newsID") %>
<html>
<script language="JavaScript" src="../jsscripts/loadpage.js"></script>
<script language="javascript" type="text/javascript">
<!--
if (top.location == self.location) { //if page is not in its frameset
top.location.href = "index2.asp" + "?newsID=<%=strNewsID%>" ;
}
//-->
</script>
then, in the new frameset building page I made - I turned it from index.htm to index.asp and simply called the passed query string as such:
<%strNewsID = Request.querystring("newsID") %>
... start of page stuff<script LANGUAGE="JavaScript">
document.writeln('<frameset framespacing="0" border="0" frameborder="0" rows="100,27,*">');
(.... blah blah.. frameset stuff ...)
document.writeln(' <frame name="main" src="news_item.asp?newsID=<%=strNewsID%>" frameborder="0" marginwidth="10" marginheight="10" scrolling="auto" noresize>');
document.writeln(' </frameset>');
...
... etc
I must be tired.. it's not that hard a concept.. it just required me to leave my little box of "must use existing frameset and code!".. which of course.. I didn't have to
<sound of web designer bashing head against keyboard>god I can't believe this client is still insisting on using frames.. </sound of web designer bashing head against keyboard>
cheers folks
-s42