Dynamic frame loading using JavaScript

I have a frame based site which I would like to be able to specify what is loaded in the frameset using JavaScript.

I had in mind to use something like:

index.html?Page=ThisPage

and then in the frameset definition so something like


    var QueryString = document.location.href+"";
    QueryString = QueryString.slice(QueryString.lastIndexOf("?")); // Extract any inpur parameters...
    if(QueryString == "" || QueryString == "undefined") QueryString = "main.html";
    document.write('<frame name="mainFrame" src="'+QueryString+'" scrolling="AUTO" noresize marginwidth="0" marginheight="0">');

However this doesn’t seem to work. Is something of this nature possible? Am I close or way off the mark?

I got this from someone else and it works pretty well:
<html>
<head>
<title>Frame Print Demo</title>
<script language=“JavaScript”>
function frame_saver()
{
if (self.location.search)
{
parent.frameb.location = location.search.substring(1,location.search.length);
}
}
window.onload = frame_saver;
</script>
</head>
<frameset rows=“25%,*” border=“1”>
<frame src=“looka.html” name=“framea”>
<frame src=“lookb.html” name=“frameb”>
</frameset>

The frame “framb” has a default page in case something is not passed in location.search.

Cheers mate, this also seems to work

<!doctype html public "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<title>Customade HR System</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<script>var MainFrame = document.location.search; MainFrame = MainFrame.slice(MainFrame.lastIndexOf('?')+1);if(MainFrame == "" || MainFrame == 'undefined') MainFrame = "main.html";;
  document.write('<frameset rows="102,*" frameborder="NO" border="0" framespacing="0">');
  document.write('<frame name="mastFrame" scrolling="NO" noresize src="mast.asp">');
  document.write('<frameset cols="160,*" frameborder="NO" border="0" framespacing="0">');
    document.write('<frame name="menuFrame" scrolling="AUTO" noresize src="menu.asp?Page=Cms" >');
    document.write('<frame name="mainFrame" scrolling="AUTO" frameborder="no" frameborder="no" src="'+MainFrame+'">');
  document.write('</frameset>');
document.write('</frameset>');
</script>
<noframes>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</noframes>
</html>

A definite advantage to the method I posted is that it loads the requested page straight away, whereas with the simplier method the default page is visable for a short period before it reloads. Anyway, seems to work well.