/    Sign up×
Community /Pin to ProfileBookmark

[HELP] Play sound once per day on Webpage

Hi Everyone.

I am trying to get the main page on my website to play a small sound clip when a visitor comes to the site for the first time each day, or for the first time in a 24 hour period. I know HTML, but not any other web design languages like css or javascript. I’m hoping someone here might be able to help me get this concept to work. I am not against using javascript and can take pre-written javascript and modify it to work on my website, I just don’t know enough to code something like this from scratch.

I was thinking that maybe the use of cookies would help the webpage determine if this is the first time the visitor has been to the site in the last 24 hours. I’ve never used cookies on my web sites before, so that too is something that I don’t know much about.

If anyone can help me I’d truly appreciate it.

Thank you in advance.

John

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@ray326Jan 28.2007 — Yes, you'll need to use cookies. I'll move this to the Javascript forum since that's the most likely mechanism although server side is the most robust way.
Copy linkTweet thisAlerts:
@ngpgeetaJan 28.2007 — Here is the code for playing sound once in a day. Hope this helps!

<HTML>

<HEAD>

<TITLE> New Document </TITLE>

<script>

function name(c,n)

{

var pairs=c.split(";")

for(var i=0;i<pairs.length;++i)

{

var pairSplit=pairs[i].split("=")

if(pairSplit[0]==n)return true

}

return false

}



function getCookieValue(c,n)

{

var pairs=c.split(";")

for(var i=0;i<pairs.length;++i)

{

var pairSplit=pairs[i].split("=")

if(pairSplit[0]==n)return pairSplit[1]

}

return ""



}



function pageCounter()

{

readCookie()

displayPage()

}





function displayPage()

{

if(counter==0)

{

alert("You are visiting this page for the first time today.")

window.location.href="c:windowsMediachimes.wav"

}

else alert("Welcome for visiting again.")

}



function readCookie()

{

var dt= new Date()

var day= dt.getDate()

var month=dt.getMonth()

var year=dt.getYear()

var curdate=day+"/"+month+"/"+year



var cookie=document.cookie

var val

counter=0



if(name(cookie,"count"))

{

val=getCookieValue(cookie,"count")

if(val==curdate)

counter=1

}



var newCookie="count="+curdate

newCookie+=";"

window.document.cookie=newCookie

}





</script>

</HEAD>



<BODY onLoad="pageCounter()">





</BODY>

</HTML>
×

Success!

Help @Draugr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...