Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 18th, 2004, 02:01 PM
Registered User
 
Join Date: Jul 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Use cookie to set main frame

Hello,

I'm trying to use a cookie to set what the main frame will load as content. Basically, if the user enters the site one way I need the main frame to display a specific page that contains the information stored in the cookie as part of the filename of the source. If they enter a different way I would like the default page to load. Currently the header loads fine as it is hard coded into the page, but the main frame loads nothing. At this point the pages that load as header and main are unimportant, I more just need the code to work and I'll worry about correct pages later.

I've enclosed all of my code below. I'm new to javascript and hope I'm just missing something simple.

Any help would be greatly appreciated.

Thanks,

Nathan

<html>
<head>

<SCRIPT LANGUAGE="JavaScript">

cookie_name = "dataCookie";
var YouWrote;
var mainpage;

function getName() {
if(document.cookie)
{
index = document.cookie.indexOf(cookie_name);
if (index != -1)
{
namestart = (document.cookie.indexOf("=", index) + 1);
nameend = document.cookie.indexOf(";", index);
if (nameend == -1) {nameend = document.cookie.length;}
YouWrote = document.cookie.substring(namestart, nameend);
return YouWrote;
}
}
}
function getpage(){
YouWrote=getName();

if (YouWrote == "dataCookie")
{YouWrote = "Nothing_Entered"}

if (YouWrote == "Nothing_Entered")
{window.main.src="mainframespecific.htm"}
if (YouWrote = "Nothing Entered")
{window.main.src="mainframedefault.htm"}
}

</SCRIPT>

<base href="~~base_href$~~">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Welcome to the Main Page</title>
<script language="JavaScript" src="iwwiab.js"></script>
</head>
<frameset rows="175,*" frameborder=0 framespacing=0 border=0 >
<frame src="mainpageheader.htm" scrolling="no" name="top" marginwidth="0" marginheight="2">
<frame name="main" marginwidth="0" marginheight="2">
<script>getpage()</script>


<noframes>
<body>
<p>This page requires a frames capable browser.</p>
</body>
</noframes>
</frameset>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set one frame src from other frame akumarp2p ASP.NET 1.x and 2.0 Application Design 2 March 13th, 2007 04:13 AM
set the cookie file name crmpicco Javascript How-To 4 February 17th, 2006 05:04 AM
Set Cookie Chapter 8 ? phirun BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 13 May 27th, 2005 11:19 AM
Set Cookie rowlandk Beginning PHP 5 April 6th, 2004 01:18 PM
Target for main frame? Snib Javascript How-To 6 December 13th, 2003 04:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.