Background Sound

P

Pete

I have added a background sound to my homepage only. So this plays whenever
the homepage is opened. Is it possible to configure this so it only plays
when the homepage is opened by a visitor for the first time & not everytime
you return to the homepage from other pages on the website ?
 
T

Thomas A. Rowe

You would need to look into writing a cookie.
http://en.wikipedia.org/wiki/HTTP_cookie
--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================
 
T

Trevor L.

Thomas,
I think the poster wants to have the music play only when anyone first
visits the home page in a session, and when coming back to the home page
from another page in the site, in that session, to have it *not* play. If
the person visits a second time - not from within the site - then the music
should still play.

Do I understand this correctly?
If so, does this necessarily need a cookie - wouldn't this prevent the music
from playing on the second and subsequent time of entering the home page ?

My thoughts are that when returning to the home page from another page, the
location is coded as index.html?revisit=yes and index.html then extracts the
parameter revisit and when yes, does not play the music.

As I have a similar situation, I will try this out. If I succeed, I will
post a response with the details.
 
T

Thomas A. Rowe

This would be best done with a cookie that expires, in say 24 hours.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================
 
T

Trevor L.

Thomas,

I took your advice and tried to create a cookie as per
http://en.wikipedia.org/wiki/HTTP_cookie

I used this code:
<script type="text/javascript">
if (document.cookie)
{ document.cookie = "play=yes; expires=; path=/";
alert('cookie=' + document.cookie) }
else alert("cookie can't be set")
</script>

What returned was the alert
cookie can't be set

Why?
I am testing on my local disk. Should I test on the web?

I tried to set my website (tandcl.homemail.com.au) as an "Always Allow" in
IE Tools | Internet options | Privacy | Sites , but it didn't come up in the
list of sites. Again, I can't figure out why!

I am fairly sure I also allow cookies from primary sites, although where I
set this, I can't remember.

Any further help appreciated
 
T

Thomas A. Rowe

I would test it on the live site.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================
 
T

Thomas A. Rowe

But then all pages would have be .asp, if ASP is the server-side scripting language supported on the
server in order to maintain the session state.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================
 
T

Trevor L.

Thomas,

I have at last tried this on the live site

My code is
function createCookie(name, value, days)
{
if (days)
{ var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
//-------------------------------
function readCookie(name)
{
var ca = document.cookie.split(';');
var nameEQ = name + "=";
for(var i=0; i < ca.length; i++)
{ var c = ca;
while (c.charAt(0)==' ')
c = c.substring(1, c.length); //delete spaces
if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length, c.length);
}
return null;
}
//-------------------------------
function playmusic()
{
document.write(
'<tr id="music"><th>'
+ ' <input type="button" class="top" value="Hide
Player"'
+ ' onclick="hideit(\'music\')";>'
+ ' <embed src="minuet.mid" id="theNoise"'
+ ' width="144" height="45" autostart="true" loop="false">'
+ '</th></tr>')
}

<script type="text/javascript">
if (readCookie('play') != 'no')
playmusic()
createcookie('play','no','0.0417')
</script>

The music plays fine very time, even after exiting the page to another page
in the same website and then returning or refreshing the page entirely

Any ideas?
 
S

Stefan B Rusynko

Don't see how your scripts can work
- what are you expecting as a Boolean result from: if (days)
- which would be processed as: if (0.0417) and not compared to anything so it would always default to the else
Check your TIF for what cookie is actually being written




| Thomas,
|
| I have at last tried this on the live site
|
| My code is
| function createCookie(name, value, days)
| {
| if (days)
| { var date = new Date();
| date.setTime(date.getTime() + (days*24*60*60*1000));
| var expires = "; expires=" + date.toGMTString();
| }
| else var expires = "";
| document.cookie = name + "=" + value + expires + "; path=/";
| }
| //-------------------------------
| function readCookie(name)
| {
| var ca = document.cookie.split(';');
| var nameEQ = name + "=";
| for(var i=0; i < ca.length; i++)
| { var c = ca;
| while (c.charAt(0)==' ')
| c = c.substring(1, c.length); //delete spaces
| if (c.indexOf(nameEQ) == 0)
| return c.substring(nameEQ.length, c.length);
| }
| return null;
| }
| //-------------------------------
| function playmusic()
| {
| document.write(
| '<tr id="music"><th>'
| + ' <input type="button" class="top" value="Hide
Player"'
| + ' onclick="hideit(\'music\')";>'
| + ' <embed src="minuet.mid" id="theNoise"'
| + ' width="144" height="45" autostart="true" loop="false">'
| + '</th></tr>')
| }
|
| <script type="text/javascript">
| if (readCookie('play') != 'no')
| playmusic()
| createcookie('play','no','0.0417')
| </script>
|
| The music plays fine very time, even after exiting the page to another page
| in the same website and then returning or refreshing the page entirely
|
| Any ideas?
| --
| Cheers,
| Trevor L.
| Website: http://tandcl.homemail.com.au
|
| Thomas A. Rowe wrote:
| > I would test it on the live site.
| >
| > --
| > ==============================================
| > Thomas A. Rowe (Microsoft MVP - FrontPage)
| > ==============================================
| > If you feel your current issue is a results of installing
| > a Service Pack or security update, please contact
| > Microsoft Product Support Services:
| > http://support.microsoft.com
| > If the problem can be shown to have been caused by a
| > security update, then there is usually no charge for the call.
| > ==============================================
| >
| > | >> Thomas,
| >>
| >> I took your advice and tried to create a cookie as per
| >> http://en.wikipedia.org/wiki/HTTP_cookie
| >>
| >> I used this code:
| >> <script type="text/javascript">
| >> if (document.cookie)
| >> { document.cookie = "play=yes; expires=; path=/";
| >> alert('cookie=' + document.cookie) }
| >> else alert("cookie can't be set")
| >> </script>
| >>
| >> What returned was the alert
| >> cookie can't be set
| >>
| >> Why?
| >> I am testing on my local disk. Should I test on the web?
| >>
| >> I tried to set my website (tandcl.homemail.com.au) as an "Always
| >> Allow" in IE Tools | Internet options | Privacy | Sites , but it
| >> didn't come up in the list of sites. Again, I can't figure out why!
| >>
| >> I am fairly sure I also allow cookies from primary sites, although
| >> where I set this, I can't remember.
| >>
| >> Any further help appreciated
| >> --
| >> Cheers,
| >> Trevor L., WIP (Web Interested Person)
| >> Website: http://tandcl.homemail.com.au
| >>
| >> Thomas A. Rowe wrote:
| >>> This would be best done with a cookie that expires, in say 24 hours.
| >>>
| >>> --
| >>> ==============================================
| >>> Thomas A. Rowe (Microsoft MVP - FrontPage)
| >>> ==============================================
| >>> If you feel your current issue is a results of installing
| >>> a Service Pack or security update, please contact
| >>> Microsoft Product Support Services:
| >>> http://support.microsoft.com
| >>> If the problem can be shown to have been caused by a
| >>> security update, then there is usually no charge for the call.
| >>> ==============================================
| >>>
| >>> | >>>> Thomas,
| >>>> I think the poster wants to have the music play only when anyone
| >>>> first visits the home page in a session, and when coming back to
| >>>> the home page from another page in the site, in that session, to have
| >>>> it *not* play. If the person visits a second time - not from
| >>>> within the site - then the music should still play. Do I understand
| >>>> this
| >>>> correctly? If so, does this necessarily need a cookie - wouldn't this
| >>>> prevent
| >>>> the music from playing on the second and subsequent time of
| >>>> entering the home page ? My thoughts are that when returning to the
| >>>> home
| >>>> page from another page, the location is coded as
| >>>> index.html?revisit=yes and index.html then extracts the parameter
| >>>> revisit and when yes, does not play the
| >>>> music. As I have a similar situation, I will try this out. If I
| >>>> succeed, I will post a response with the details.
| >>>> --
| >>>> Cheers,
| >>>> Trevor L., WIP (Web Interested Person)
| >>>> Website: http://tandcl.homemail.com.au
| >>>>
| >>>> Thomas A. Rowe wrote:
| >>>>> You would need to look into writing a cookie.
| >>>>> http://en.wikipedia.org/wiki/HTTP_cookie
| >>>>> --
| >>>>> ==============================================
| >>>>> Thomas A. Rowe (Microsoft MVP - FrontPage)
| >>>>> ==============================================
| >>>>> If you feel your current issue is a results of installing
| >>>>> a Service Pack or security update, please contact
| >>>>> Microsoft Product Support Services:
| >>>>> http://support.microsoft.com
| >>>>> If the problem can be shown to have been caused by a
| >>>>> security update, then there is usually no charge for the call.
| >>>>> ==============================================
| >>>>>
| >>>>> | >>>>>> I have added a background sound to my homepage only. So this
| >>>>>> plays whenever the homepage is opened. Is it possible to
| >>>>>> configure this so it only plays when the homepage is opened by a
| >>>>>> visitor for the first time & not everytime you return to the
| >>>>>> homepage from other pages on the website ?
|
|
 
T

Trevor L.

Stefan,
Thank you for replying.

'if (days)' is intended to test if the days parameter has been passed from
the calling code.

This is something which has always worried me. Should one test this as:
'if (days)'?
or as
'if (days == null)'?
or as
'if (days == "")'?
or as
'if (days == " ")'?

Do these test the same thing or are they completely different?

0.0417 was intended to represent one hour, but of course with rounding that
won't be true. I think the result was that the cookie didn't get created (or
if it did with an expiry date of null)

I don't know what you mean by check my TIF. However, by changing the days
parameter to 1, the cookie did get created.

I have now changed the code to:
function createCookie(name, value, days, hours)
{
if (days)
{ var newhours = days*24
if (hours)
newhours += hours

var date = new Date()
date.setTime(date.getTime() + (newhours*60*60*1000))
var expires = date.toGMTString() }
else var expires = ""
document.cookie = name + "=" + value + "; expires=" + expires + "; path=/"
}

which I call by
createCookie('play','no','0','1')

This creates a cookie with a one hour expiry date, which more or less suits
me. I would be happier if the cookie expires at the end of the session. Is
this what occurs when one sets expires=""?
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au
Don't see how your scripts can work
- what are you expecting as a Boolean result from: if (days)
- which would be processed as: if (0.0417) and not compared to
anything so it would always default to the else Check your TIF for
what cookie is actually being written




Trevor L. said:
Thomas,

I have at last tried this on the live site

My code is
function createCookie(name, value, days)
{
if (days)
{ var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
//-------------------------------
function readCookie(name)
{
var ca = document.cookie.split(';');
var nameEQ = name + "=";
for(var i=0; i < ca.length; i++)
{ var c = ca;
while (c.charAt(0)==' ')
c = c.substring(1, c.length); //delete spaces
if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length, c.length);
}
return null;
}
//-------------------------------
function playmusic()
{
document.write(
'<tr id="music"><th>'
+ ' <input type="button" class="top" value="Hide
Player"'
+ ' onclick="hideit(\'music\')";>'
+ ' <embed src="minuet.mid" id="theNoise"'
+ ' width="144" height="45" autostart="true" loop="false">'
+ '</th></tr>')
}

<script type="text/javascript">
if (readCookie('play') != 'no')
playmusic()
createcookie('play','no','0.0417')
</script>

The music plays fine very time, even after exiting the page to
another page in the same website and then returning or refreshing
the page entirely

Any ideas?
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au
I would test it on the live site.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================

Thomas,

I took your advice and tried to create a cookie as per
http://en.wikipedia.org/wiki/HTTP_cookie

I used this code:
<script type="text/javascript">
if (document.cookie)
{ document.cookie = "play=yes; expires=; path=/";
alert('cookie=' + document.cookie) }
else alert("cookie can't be set")
</script>

What returned was the alert
cookie can't be set

Why?
I am testing on my local disk. Should I test on the web?

I tried to set my website (tandcl.homemail.com.au) as an "Always
Allow" in IE Tools | Internet options | Privacy | Sites , but it
didn't come up in the list of sites. Again, I can't figure out why!

I am fairly sure I also allow cookies from primary sites, although
where I set this, I can't remember.

Any further help appreciated
--
Cheers,
Trevor L., WIP (Web Interested Person)
Website: http://tandcl.homemail.com.au

Thomas A. Rowe wrote:
This would be best done with a cookie that expires, in say 24
hours.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================

Thomas,
I think the poster wants to have the music play only when anyone
first visits the home page in a session, and when coming back to
the home page from another page in the site, in that session, to
have it *not* play. If the person visits a second time - not from
within the site - then the music should still play. Do I
understand this
correctly? If so, does this necessarily need a cookie - wouldn't
this prevent
the music from playing on the second and subsequent time of
entering the home page ? My thoughts are that when returning to
the home
page from another page, the location is coded as
index.html?revisit=yes and index.html then extracts the parameter
revisit and when yes, does not play the
music. As I have a similar situation, I will try this out. If I
succeed, I will post a response with the details.
--
Cheers,
Trevor L., WIP (Web Interested Person)
Website: http://tandcl.homemail.com.au

Thomas A. Rowe wrote:
You would need to look into writing a cookie.
http://en.wikipedia.org/wiki/HTTP_cookie
--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================

I have added a background sound to my homepage only. So this
plays whenever the homepage is opened. Is it possible to
configure this so it only plays when the homepage is opened by
a visitor for the first time & not everytime you return to the
homepage from other pages on the website ?
 
S

Stefan B Rusynko

All test are different
- a null (no assigned value) is not equal to "" (empty string) and not equal to " " (a space string)

If you are testing any IF it returns a Boolean (True/False = 1/0) based on a condition Being Met / Or Not Met.
If a value in the test is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial
value of false. All other values, including any object or the string "false", create an object with an initial value of true.

To test the value of "days" you need to compare it to something (in your case a numeric comparison, not a text comparison) as in: if
(days == 0) or if (days != 1)

By changing the days to 0 you slipped into a trap of setting it to Boolean = 0, so it always will evaluate as False
- because IF (days) when days = 0 is the same as: IF (0), which is the same as IF (False)
Yes your cookie was being created but always w/ a expires = ""

And if you do get a proper If comparison set up, you will never write a cookie when it evalues to True because your syntax has the
document.cookie inside the else part
To always write a cookie it should be in the format
if (condition test) { statements1 - your expires calc} else { statements2 - your alt expires}document.cookie.....Or write it
differently in each statementsXFYI for JS cookiesEXPIRES=dateValue specifies a date string that defines the valid life time of that
cookie. Once the expiration date has been reached, the cookie will no longer be stored or given out. If you do not specify
dateValue, the cookie expires when the user's session endsTIF - Temporary Internet Files (folder) where your cookie are supposedly
being written
Try reviewing
http://library.n0i.net/programming/javascript/js-csr13/

PS
- all that being said, if the user blocks cookies nothing in the above works
(that's why I don't rely on js cookies)




| Stefan,
| Thank you for replying.
|
| 'if (days)' is intended to test if the days parameter has been passed from
| the calling code.
|
| This is something which has always worried me. Should one test this as:
| 'if (days)'?
| or as
| 'if (days == null)'?
| or as
| 'if (days == "")'?
| or as
| 'if (days == " ")'?
|
| Do these test the same thing or are they completely different?
|
| 0.0417 was intended to represent one hour, but of course with rounding that
| won't be true. I think the result was that the cookie didn't get created (or
| if it did with an expiry date of null)
|
| I don't know what you mean by check my TIF. However, by changing the days
| parameter to 1, the cookie did get created.
|
| I have now changed the code to:
| function createCookie(name, value, days, hours)
| {
| if (days)
| { var newhours = days*24
| if (hours)
| newhours += hours
|
| var date = new Date()
| date.setTime(date.getTime() + (newhours*60*60*1000))
| var expires = date.toGMTString() }
| else var expires = ""
| document.cookie = name + "=" + value + "; expires=" + expires + "; path=/"
| }
|
| which I call by
| createCookie('play','no','0','1')
|
| This creates a cookie with a one hour expiry date, which more or less suits
| me. I would be happier if the cookie expires at the end of the session. Is
| this what occurs when one sets expires=""?
| --
| Cheers,
| Trevor L.
| Website: http://tandcl.homemail.com.au
|
| Stefan B Rusynko wrote:
| > Don't see how your scripts can work
| > - what are you expecting as a Boolean result from: if (days)
| > - which would be processed as: if (0.0417) and not compared to
| > anything so it would always default to the else Check your TIF for
| > what cookie is actually being written
| >
| > --
| >
| > _____________________________________________
| > SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
| > "Warning - Using the F1 Key will not break anything!" (-;
| > To find the best Newsgroup for FrontPage support see:
| > http://www.net-sites.com/sitebuilder/newsgroups.asp
| > _____________________________________________
| >
| >
| > | >> Thomas,
| >>
| >> I have at last tried this on the live site
| >>
| >> My code is
| >> function createCookie(name, value, days)
| >> {
| >> if (days)
| >> { var date = new Date();
| >> date.setTime(date.getTime() + (days*24*60*60*1000));
| >> var expires = "; expires=" + date.toGMTString();
| >> }
| >> else var expires = "";
| >> document.cookie = name + "=" + value + expires + "; path=/";
| >> }
| >> //-------------------------------
| >> function readCookie(name)
| >> {
| >> var ca = document.cookie.split(';');
| >> var nameEQ = name + "=";
| >> for(var i=0; i < ca.length; i++)
| >> { var c = ca;
| >> while (c.charAt(0)==' ')
| >> c = c.substring(1, c.length); //delete spaces
| >> if (c.indexOf(nameEQ) == 0)
| >> return c.substring(nameEQ.length, c.length);
| >> }
| >> return null;
| >> }
| >> //-------------------------------
| >> function playmusic()
| >> {
| >> document.write(
| >> '<tr id="music"><th>'
| >> + ' <input type="button" class="top" value="Hide
Player"'
| >> + ' onclick="hideit(\'music\')";>'
| >> + ' <embed src="minuet.mid" id="theNoise"'
| >> + ' width="144" height="45" autostart="true" loop="false">'
| >> + '</th></tr>')
| >> }
| >>
| >> <script type="text/javascript">
| >> if (readCookie('play') != 'no')
| >> playmusic()
| >> createcookie('play','no','0.0417')
| >> </script>
| >>
| >> The music plays fine very time, even after exiting the page to
| >> another page in the same website and then returning or refreshing
| >> the page entirely
| >>
| >> Any ideas?
| >> --
| >> Cheers,
| >> Trevor L.
| >> Website: http://tandcl.homemail.com.au
| >>
| >> Thomas A. Rowe wrote:
| >>> I would test it on the live site.
| >>>
| >>> --
| >>> ==============================================
| >>> Thomas A. Rowe (Microsoft MVP - FrontPage)
| >>> ==============================================
| >>> If you feel your current issue is a results of installing
| >>> a Service Pack or security update, please contact
| >>> Microsoft Product Support Services:
| >>> http://support.microsoft.com
| >>> If the problem can be shown to have been caused by a
| >>> security update, then there is usually no charge for the call.
| >>> ==============================================
| >>>
| >>> | >>>> Thomas,
| >>>>
| >>>> I took your advice and tried to create a cookie as per
| >>>> http://en.wikipedia.org/wiki/HTTP_cookie
| >>>>
| >>>> I used this code:
| >>>> <script type="text/javascript">
| >>>> if (document.cookie)
| >>>> { document.cookie = "play=yes; expires=; path=/";
| >>>> alert('cookie=' + document.cookie) }
| >>>> else alert("cookie can't be set")
| >>>> </script>
| >>>>
| >>>> What returned was the alert
| >>>> cookie can't be set
| >>>>
| >>>> Why?
| >>>> I am testing on my local disk. Should I test on the web?
| >>>>
| >>>> I tried to set my website (tandcl.homemail.com.au) as an "Always
| >>>> Allow" in IE Tools | Internet options | Privacy | Sites , but it
| >>>> didn't come up in the list of sites. Again, I can't figure out why!
| >>>>
| >>>> I am fairly sure I also allow cookies from primary sites, although
| >>>> where I set this, I can't remember.
| >>>>
| >>>> Any further help appreciated
| >>>> --
| >>>> Cheers,
| >>>> Trevor L., WIP (Web Interested Person)
| >>>> Website: http://tandcl.homemail.com.au
| >>>>
| >>>> Thomas A. Rowe wrote:
| >>>>> This would be best done with a cookie that expires, in say 24
| >>>>> hours.
| >>>>>
| >>>>> --
| >>>>> ==============================================
| >>>>> Thomas A. Rowe (Microsoft MVP - FrontPage)
| >>>>> ==============================================
| >>>>> If you feel your current issue is a results of installing
| >>>>> a Service Pack or security update, please contact
| >>>>> Microsoft Product Support Services:
| >>>>> http://support.microsoft.com
| >>>>> If the problem can be shown to have been caused by a
| >>>>> security update, then there is usually no charge for the call.
| >>>>> ==============================================
| >>>>>
| >>>>> | >>>>>> Thomas,
| >>>>>> I think the poster wants to have the music play only when anyone
| >>>>>> first visits the home page in a session, and when coming back to
| >>>>>> the home page from another page in the site, in that session, to
| >>>>>> have it *not* play. If the person visits a second time - not from
| >>>>>> within the site - then the music should still play. Do I
| >>>>>> understand this
| >>>>>> correctly? If so, does this necessarily need a cookie - wouldn't
| >>>>>> this prevent
| >>>>>> the music from playing on the second and subsequent time of
| >>>>>> entering the home page ? My thoughts are that when returning to
| >>>>>> the home
| >>>>>> page from another page, the location is coded as
| >>>>>> index.html?revisit=yes and index.html then extracts the parameter
| >>>>>> revisit and when yes, does not play the
| >>>>>> music. As I have a similar situation, I will try this out. If I
| >>>>>> succeed, I will post a response with the details.
| >>>>>> --
| >>>>>> Cheers,
| >>>>>> Trevor L., WIP (Web Interested Person)
| >>>>>> Website: http://tandcl.homemail.com.au
| >>>>>>
| >>>>>> Thomas A. Rowe wrote:
| >>>>>>> You would need to look into writing a cookie.
| >>>>>>> http://en.wikipedia.org/wiki/HTTP_cookie
| >>>>>>> --
| >>>>>>> ==============================================
| >>>>>>> Thomas A. Rowe (Microsoft MVP - FrontPage)
| >>>>>>> ==============================================
| >>>>>>> If you feel your current issue is a results of installing
| >>>>>>> a Service Pack or security update, please contact
| >>>>>>> Microsoft Product Support Services:
| >>>>>>> http://support.microsoft.com
| >>>>>>> If the problem can be shown to have been caused by a
| >>>>>>> security update, then there is usually no charge for the call.
| >>>>>>> ==============================================
| >>>>>>>
| >>>>>>> | >>>>>>>> I have added a background sound to my homepage only. So this
| >>>>>>>> plays whenever the homepage is opened. Is it possible to
| >>>>>>>> configure this so it only plays when the homepage is opened by
| >>>>>>>> a visitor for the first time & not everytime you return to the
| >>>>>>>> homepage from other pages on the website ?
|
|
 
T

Trevor L.

Thanks, Stefan
I have to think this through.

I understand the difference between null, empty and space. I just have to
figure what to test for when different parameters are passed.

e.g. with createCookie('play','no','0','1') , days would be 0 and the test
'if (days)' would return false (Correct?)

What about createCookie('play','no',,'1') ?
Does this return null?

And createCookie('play','no','','1') ?
Does this return empty?

If either of these, 'if(days)' will still return false, won't it ?

BTW, I think my syntax was correct
I had
if (days)
{... var expires = date.toGMTString() }
else var expires = ""
document.cookie

The brackets are assumed, aren't they?
i.e. the code is actually read as
if (days)
{... var expires = date.toGMTString() }
else
{var expires = ""}
document.cookie

and document.cookie is outside both paths of the test.
Correct?

Thanks for referring me to TIF (I didn't know what this was at first ,
confusing it with TIFF, which is an image file format, so I thought).

I will try to do this. The name of the cookie is what ?
C:\Documents and Settings\Trevor\Local Settings\Temporary Internet
Files\Cookie:[email protected]/ ?

Yes, I now that persons who block cookies won't see it, but I will try to
make the result fail safe
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au
All test are different
- a null (no assigned value) is not equal to "" (empty string) and
not equal to " " (a space string)

If you are testing any IF it returns a Boolean (True/False = 1/0)
based on a condition Being Met / Or Not Met.
If a value in the test is omitted or is 0, -0, null, false, NaN,
undefined, or the empty string (""), the object has an initial value
of false. All other values, including any object or the string
"false", create an object with an initial value of true.

To test the value of "days" you need to compare it to something (in
your case a numeric comparison, not a text comparison) as in: if
(days == 0) or if (days != 1)

By changing the days to 0 you slipped into a trap of setting it to
Boolean = 0, so it always will evaluate as False - because IF (days)
when days = 0 is the same as: IF (0), which is the same as IF (False)
Yes your cookie was being created but always w/ a expires = ""

And if you do get a proper If comparison set up, you will never write
a cookie when it evalues to True because your syntax has the
document.cookie inside the else part
To always write a cookie it should be in the format
if (condition test) { statements1 - your expires calc} else {
statements2 - your alt expires}document.cookie.....Or write it
differently in each statementsXFYI for JS cookiesEXPIRES=dateValue
specifies a date string that defines the valid life time of that
cookie. Once the expiration date has been reached, the cookie will no
longer be stored or given out. If you do not specify dateValue, the
cookie expires when the user's session endsTIF - Temporary Internet
Files (folder) where your cookie are supposedly being written
Try reviewing
http://library.n0i.net/programming/javascript/js-csr13/

PS
- all that being said, if the user blocks cookies nothing in the
above works (that's why I don't rely on js cookies)




Trevor L. said:
Stefan,
Thank you for replying.

'if (days)' is intended to test if the days parameter has been
passed from the calling code.

This is something which has always worried me. Should one test this
as: 'if (days)'?
or as
'if (days == null)'?
or as
'if (days == "")'?
or as
'if (days == " ")'?

Do these test the same thing or are they completely different?

0.0417 was intended to represent one hour, but of course with
rounding that won't be true. I think the result was that the cookie
didn't get created (or if it did with an expiry date of null)

I don't know what you mean by check my TIF. However, by changing the
days parameter to 1, the cookie did get created.

I have now changed the code to:
function createCookie(name, value, days, hours)
{
if (days)
{ var newhours = days*24
if (hours)
newhours += hours

var date = new Date()
date.setTime(date.getTime() + (newhours*60*60*1000))
var expires = date.toGMTString() }
else var expires = ""
document.cookie = name + "=" + value + "; expires=" + expires + ";
path=/" }

which I call by
createCookie('play','no','0','1')

This creates a cookie with a one hour expiry date, which more or
less suits me. I would be happier if the cookie expires at the end
of the session. Is this what occurs when one sets expires=""?
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au
Don't see how your scripts can work
- what are you expecting as a Boolean result from: if (days)
- which would be processed as: if (0.0417) and not compared to
anything so it would always default to the else Check your TIF for
what cookie is actually being written




Thomas,

I have at last tried this on the live site

My code is
function createCookie(name, value, days)
{
if (days)
{ var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
//-------------------------------
function readCookie(name)
{
var ca = document.cookie.split(';');
var nameEQ = name + "=";
for(var i=0; i < ca.length; i++)
{ var c = ca;
while (c.charAt(0)==' ')
c = c.substring(1, c.length); //delete spaces
if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length, c.length);
}
return null;
}
//-------------------------------
function playmusic()
{
document.write(
'<tr id="music"><th>'
+ ' <input type="button" class="top" value="Hide
Player"'
+ ' onclick="hideit(\'music\')";>'
+ ' <embed src="minuet.mid" id="theNoise"'
+ ' width="144" height="45" autostart="true" loop="false">'
+ '</th></tr>')
}

<script type="text/javascript">
if (readCookie('play') != 'no')
playmusic()
createcookie('play','no','0.0417')
</script>

The music plays fine very time, even after exiting the page to
another page in the same website and then returning or refreshing
the page entirely

Any ideas?
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au

Thomas A. Rowe wrote:
I would test it on the live site.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================

Thomas,

I took your advice and tried to create a cookie as per
http://en.wikipedia.org/wiki/HTTP_cookie

I used this code:
<script type="text/javascript">
if (document.cookie)
{ document.cookie = "play=yes; expires=; path=/";
alert('cookie=' + document.cookie) }
else alert("cookie can't be set")
</script>

What returned was the alert
cookie can't be set

Why?
I am testing on my local disk. Should I test on the web?

I tried to set my website (tandcl.homemail.com.au) as an "Always
Allow" in IE Tools | Internet options | Privacy | Sites , but it
didn't come up in the list of sites. Again, I can't figure out
why!

I am fairly sure I also allow cookies from primary sites,
although where I set this, I can't remember.

Any further help appreciated
--
Cheers,
Trevor L., WIP (Web Interested Person)
Website: http://tandcl.homemail.com.au

Thomas A. Rowe wrote:
This would be best done with a cookie that expires, in say 24
hours.

--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================

Thomas,
I think the poster wants to have the music play only when
anyone first visits the home page in a session, and when
coming back to the home page from another page in the site, in
that session, to have it *not* play. If the person visits a
second time - not from within the site - then the music should
still play. Do I understand this
correctly? If so, does this necessarily need a cookie -
wouldn't this prevent
the music from playing on the second and subsequent time of
entering the home page ? My thoughts are that when returning to
the home
page from another page, the location is coded as
index.html?revisit=yes and index.html then extracts the
parameter revisit and when yes, does not play the
music. As I have a similar situation, I will try this out. If I
succeed, I will post a response with the details.
--
Cheers,
Trevor L., WIP (Web Interested Person)
Website: http://tandcl.homemail.com.au

Thomas A. Rowe wrote:
You would need to look into writing a cookie.
http://en.wikipedia.org/wiki/HTTP_cookie
--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
==============================================
If you feel your current issue is a results of installing
a Service Pack or security update, please contact
Microsoft Product Support Services:
http://support.microsoft.com
If the problem can be shown to have been caused by a
security update, then there is usually no charge for the call.
==============================================

I have added a background sound to my homepage only. So this
plays whenever the homepage is opened. Is it possible to
configure this so it only plays when the homepage is opened
by a visitor for the first time & not everytime you return
to the homepage from other pages on the website ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top