Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Play sound when entering site using JavaScript and Cookies
Old 11-03-2008, 07:20 PM Play sound when entering site using JavaScript and Cookies
Novice Talker

Posts: 6
Name: SLI
Trades: 0
I only have access to 2 fields. The head and body section and I can only edit inside these tags not these actual tags. What I'm needing is to play a mp3 sound upon entering the site but I can only have it played once. Even if the back button is hit. So I was thinking cookie via JavaScript. Here's what I have but I'm just starting with JS and need some help.

Code:
<script language="javascript">
if (!getCookie('lastClip')) {document.write('<EMBED SRC="http://www.domain.com/mp3file.mp3" AUTOSTART="true" VOLUME="50" HEIGHT="60" WIDTH="144" HIDDEN="TRUE">')
setCookie('lastClip',true,3600000)
}
</script>
Guest85 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-06-2008, 02:28 AM Re: Play sound when entering site using JavaScript and Cookies
Average Talker

Posts: 25
Trades: 0
use the code below:
Quote:
<script language="javascript">
function getCookie(name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while(i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
{
return getCookieVal(j);
}
i = document.cookie.indexOf(" ", i) + 1;
if(i == 0) break;
}
return;
}
// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure)
{
if(expires){var dt=new Date();dt.setTime(dt.getTime() + expires);}
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + dt.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain)
{
if(getCookie(name))
{
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

if (!getCookie('lastClip')) {document.write('<EMBED SRC="http://www.domain.com/mp3file.mp3" AUTOSTART="true" VOLUME="50" HEIGHT="60" WIDTH="144" HIDDEN="TRUE">');
}
setCookie('lastClip',true,3600000);
</script>
__________________
Impossible means I'm possible.
softhink is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Play sound when entering site using JavaScript and Cookies
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17266 seconds with 12 queries