Forums
This topic is locked
Address frame by name not content
16 May 2003 13:07:41 Kelley B posted:
Hi. I have created a page with 3 Frames, Header, Menu and Main. I want to change the main frame contents after first view (as it is an introduction) however I have buttons, some to external pages, when these pages are closed they return visitors to the main frame, which returns to the introduction page. Is there a way I can link these buttons to main frame and not its contents as this will change almost daily. I have used reamWeaver MX for my creation.Thankyou Kelley
Replies
Replied 20 May 2003 06:27:14
20 May 2003 06:27:14 james crellin replied:
Hey Kelley--
Welcome to DMXzone. I have not tried what you are asking but i found a javascript that sets a cookie on a clients machine and counts the number of visits. Based on the number of visits, it will redirect them to the correct page. I'm not sure if it is going to work on a layout using frames but i dont see why not. I am still learning Javascript but it seems that this is pretty much customizable if you read and look at the code.
Place this code into the "main" page. The first time that someone views the page, it will set a cookie. Then, the next time it will look for that cookie and if it finds that cookie then it will redirect them. The only problem I see with this if the visitor has cleared their cookies then it will not find the cookie.
Here is the code:
==========================================
<html>
<head>
<script type=text/javascript>
var TEST_ONLY = true;// set to false to not run this in test mode
/// BEGIN COOKIE CONSTRUCT
function Cookie(document,name,hours,path,domain,secure) {
// any VAR in "this" that does not start with a "$" will
// be written into the cookie (read from also)
this.$doc = document
this.$name = name
if (hours) this.$expiration=new Date((new Date()).getTime()+hours*3600000); else this.$expiration = null
if (path) this.$path = path; else this.$path = null
if (domain) this.$domain = domain; else this.$domain = null
if (secure) this.$secure = true; else this.$secure = false
}
function CookieWrite() {
var cookieval=""
for(var prop in this) {
if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function') || prop == '') continue
if (cookieval != ""
cookieval += '&'
cookieval+=prop+":"+escape(this[prop])
}
var cookie=this.$name+"="+cookieval
if (this.$expiration) cookie+='; expires=' + this.$expiration.toGMTString()
if (this.$path) cookie+='; path=' + this.$path
if (this.$domain) cookie+='; domain=' + this.$domain
if (this.$secure) cookie+='; secure'
this.$doc.cookie=cookie
}
function CookieRead() {
var allcookies=this.$doc.cookie
if (allcookies==""
{
return false
}
var start= allcookies.indexOf(this.$name+'=')
if (start== -1) {
return false
}
start += this.$name.length+1
var end=allcookies.indexOf(';',start)
if (end == -1) end=allcookies.length
var cookieval = allcookies.substring(start,end)
var a = cookieval.split('&')
for (var i=0;i<a.length;i++) a[i]=a[i].split(':')
for (var i=0;i<a.length;i++) this[a[i][0]]=unescape(a[i][1])
return true
}
function CookieDelete() {
var cookie = this.$name+'='
if (this.$path) cookie+='; path='+this.$path
if (this.$domain) cookie+='; domain='+this.$domain
cookie+='; expires=Fri, 02-Jan-1970 00:00:00 GMT' // MAKE IT EXPIRE!
this.$doc.cookie=cookie
}
new Cookie()
Cookie.prototype.write = CookieWrite
Cookie.prototype.del = CookieDelete
Cookie.prototype.read = CookieRead
/// END COOKIE CONSTRUCT
</script>
<script>
// The following script determines if this is a first time user
// [based upon a cookie counter value]
// If it is it makes sure that the user goes to page #1 first.
// It checks to find out what page # the user should be on,
// If the user is on that page it allows the rest of the page to load,
// otherwise the user is sent to the proper page.
// If the user is on the correct page the cookie counter is incremented
// so that the next page the user can look at is the next # page.
var myCookie = new Cookie(document,"myMagicNumber",365); // expire in 1 year.
if (!myCookie.read() || !myCookie.counter)
myCookie.counter = 1; // first visit!
myCookie.write(); // store off the cookie!
var _loc = document.location.toString();
// This example assumes that the location/address of this page
// looks something like this:
// www.yoursite.com/magictrick_#.html where # is 0, 1, 2, 3, 4...
var _basePage = "www.yoursite.com/";
var _pageName = "magictrick_";
var newPage = _pageName+myCookie.counter+".html";
if (_loc.indexOf(newPage)==-1) {
// we are not on the right page - load the correct one
if (!TEST_ONLY)
document.location = _basePage+newPage;
}
// if the logic gets this far then the user is on the correct page.
myCookie.counter++;
myCookie.write();
function clearCookie() { myCookie.del(); }
</script>
</head>
<body>
<script>
if (TEST_ONLY)
document.write("loading page "+_basePage+newPage); // test line only to show what it is doing..
document.write("<BR>Your cookie number/count is "+myCookie.counter+"<BR>"
;
</script>
<BR>
<!-- this is only here to show how to do this -->
<a href="javascript:clearCookie()">clear out cookie</a>
<center><a href='www.js-examples.com'>JS-Examples.com</a></center>
</body>
</html>
============================================
I am going to try this out also and see what i come up with. If I can explain it better then I will let you know. Good Luck!
-=- saleblitz
<img src="www.syndicprint.com/o_chacon/jtc_sig.gif" border=0>
"The greatest trick the devil ever pulled was convincing the world he didn't exist." =- The Usual Suspects
Welcome to DMXzone. I have not tried what you are asking but i found a javascript that sets a cookie on a clients machine and counts the number of visits. Based on the number of visits, it will redirect them to the correct page. I'm not sure if it is going to work on a layout using frames but i dont see why not. I am still learning Javascript but it seems that this is pretty much customizable if you read and look at the code.
Place this code into the "main" page. The first time that someone views the page, it will set a cookie. Then, the next time it will look for that cookie and if it finds that cookie then it will redirect them. The only problem I see with this if the visitor has cleared their cookies then it will not find the cookie.
Here is the code:
==========================================
<html>
<head>
<script type=text/javascript>
var TEST_ONLY = true;// set to false to not run this in test mode
/// BEGIN COOKIE CONSTRUCT
function Cookie(document,name,hours,path,domain,secure) {
// any VAR in "this" that does not start with a "$" will
// be written into the cookie (read from also)
this.$doc = document
this.$name = name
if (hours) this.$expiration=new Date((new Date()).getTime()+hours*3600000); else this.$expiration = null
if (path) this.$path = path; else this.$path = null
if (domain) this.$domain = domain; else this.$domain = null
if (secure) this.$secure = true; else this.$secure = false
}
function CookieWrite() {
var cookieval=""
for(var prop in this) {
if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function') || prop == '') continue
if (cookieval != ""

cookieval+=prop+":"+escape(this[prop])
}
var cookie=this.$name+"="+cookieval
if (this.$expiration) cookie+='; expires=' + this.$expiration.toGMTString()
if (this.$path) cookie+='; path=' + this.$path
if (this.$domain) cookie+='; domain=' + this.$domain
if (this.$secure) cookie+='; secure'
this.$doc.cookie=cookie
}
function CookieRead() {
var allcookies=this.$doc.cookie
if (allcookies==""

return false
}
var start= allcookies.indexOf(this.$name+'=')
if (start== -1) {
return false
}
start += this.$name.length+1
var end=allcookies.indexOf(';',start)
if (end == -1) end=allcookies.length
var cookieval = allcookies.substring(start,end)
var a = cookieval.split('&')
for (var i=0;i<a.length;i++) a[i]=a[i].split(':')
for (var i=0;i<a.length;i++) this[a[i][0]]=unescape(a[i][1])
return true
}
function CookieDelete() {
var cookie = this.$name+'='
if (this.$path) cookie+='; path='+this.$path
if (this.$domain) cookie+='; domain='+this.$domain
cookie+='; expires=Fri, 02-Jan-1970 00:00:00 GMT' // MAKE IT EXPIRE!
this.$doc.cookie=cookie
}
new Cookie()
Cookie.prototype.write = CookieWrite
Cookie.prototype.del = CookieDelete
Cookie.prototype.read = CookieRead
/// END COOKIE CONSTRUCT
</script>
<script>
// The following script determines if this is a first time user
// [based upon a cookie counter value]
// If it is it makes sure that the user goes to page #1 first.
// It checks to find out what page # the user should be on,
// If the user is on that page it allows the rest of the page to load,
// otherwise the user is sent to the proper page.
// If the user is on the correct page the cookie counter is incremented
// so that the next page the user can look at is the next # page.
var myCookie = new Cookie(document,"myMagicNumber",365); // expire in 1 year.
if (!myCookie.read() || !myCookie.counter)
myCookie.counter = 1; // first visit!
myCookie.write(); // store off the cookie!
var _loc = document.location.toString();
// This example assumes that the location/address of this page
// looks something like this:
// www.yoursite.com/magictrick_#.html where # is 0, 1, 2, 3, 4...
var _basePage = "www.yoursite.com/";
var _pageName = "magictrick_";
var newPage = _pageName+myCookie.counter+".html";
if (_loc.indexOf(newPage)==-1) {
// we are not on the right page - load the correct one
if (!TEST_ONLY)
document.location = _basePage+newPage;
}
// if the logic gets this far then the user is on the correct page.
myCookie.counter++;
myCookie.write();
function clearCookie() { myCookie.del(); }
</script>
</head>
<body>
<script>
if (TEST_ONLY)
document.write("loading page "+_basePage+newPage); // test line only to show what it is doing..
document.write("<BR>Your cookie number/count is "+myCookie.counter+"<BR>"

</script>
<BR>
<!-- this is only here to show how to do this -->
<a href="javascript:clearCookie()">clear out cookie</a>
<center><a href='www.js-examples.com'>JS-Examples.com</a></center>
</body>
</html>
============================================
I am going to try this out also and see what i come up with. If I can explain it better then I will let you know. Good Luck!
-=- saleblitz
<img src="www.syndicprint.com/o_chacon/jtc_sig.gif" border=0>
"The greatest trick the devil ever pulled was convincing the world he didn't exist." =- The Usual Suspects
Replied 20 May 2003 22:26:26
20 May 2003 22:26:26 Kelley B replied:
Hi saleblitz, thankyou both for the welcome and the script, which though is a useful script to have doesn't fix my problem unfortunately.
My site opens with opening.htm displayed in the "main" frame, after first visit they will see current.htm displayed, they can display any of 5 different pages in the "main" frame each with a "close" link (button) back to "main". I have found some will use these buttons to explore the site on first visit while others on second or subsequent visits. I could I suppose take the lazy way out and have the opening.htm display as a popup onload and have current.htm as the "main" page, though in my opinion not really professional.
Thankyou for your time and trouble though.
kindest regards. kelley
My site opens with opening.htm displayed in the "main" frame, after first visit they will see current.htm displayed, they can display any of 5 different pages in the "main" frame each with a "close" link (button) back to "main". I have found some will use these buttons to explore the site on first visit while others on second or subsequent visits. I could I suppose take the lazy way out and have the opening.htm display as a popup onload and have current.htm as the "main" page, though in my opinion not really professional.
Thankyou for your time and trouble though.
kindest regards. kelley