View Full Version : Need to Stop Music Playing for New Visitors

01-07-2012, 07:31 AM
Our website normally plays music onload that can be stopped when manually starting a video using onclick="stop1()".

I've manipulated a javascript that detects if the user is a new or return user and plays the video automatically in a popup if the user is new. But, I cannot figure out how to either stop the music or prevent the music from starting at the same time.

I've really got no experience with js and am fumbling my way around. would appreciate your help.

Philip M
01-07-2012, 09:17 AM
Playing unrequested music or unrequested videos on a website is a terrible idea, and is sure to drive your visitors away.

And all modern browsers block unrequested popups.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

01-07-2012, 04:26 PM
Yes, I agree. But, that's what they want despite my kicking and screaming. I just need someone to actually help me instead of keep telling me it's a bad idea. I know it's a bad idea!

Philip M
01-07-2012, 06:13 PM
Yes, I agree. But, that's what they want despite my kicking and screaming. I just need someone to actually help me instead of keep telling me it's a bad idea. I know it's a bad idea!

Well, that is not easy if you do not show your (relevant) code. :rolleyes:

Your bosses are sadly lacking in intelligence if they ignore advice from people with a lot of experience of these things. Many people erase their cookies at frequent intervals - I erase my every day - so they will always be new users, and forced to watch the $#^@*&^*!# video. You can be sure that they will click on the red X and aim for a competitor's site.

Show your boss this thread - and suggest that he sees sense and changes his mind. If he won't, you should seriously start thinking about finding another job, as I predict that the firm will not be in business much longer.

01-07-2012, 11:19 PM
For the particular application, doing it this way shouldn't irritate many of their visitors. This is for a church website; their demographic is mostly up-to-date with technology, but not necessarily tech-savvy. I doubt 90% of them have ever reset their cookies. But, I don't think the popup will be that effective because the same 90% will be using browser defaults and probably never see the "Allow Popups From This Site" badge. Either way, they're my client and if they insist on something I'll do it.

Here is the popup script in the body:

<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 "here";
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;
return null;
var visit=GetCookie("COOKIE1");
if (visit==null){
var expire=new Date();
window.name = "thiswin";
newwin=open("Project25/P25_Popup.php", "dispwin",
expire=new Date(expire.getTime()+7776000000);
document.cookie="COOKIE1=here; expires="+expire;

// -->

Here is the audio script in the head

<script language="javascript">
function getPlayer(movieName)
if (navigator.appName.indexOf("Microsoft") != -1)
return window[movieName];
return document[movieName];

function stop1()

Here is the manual video link that popups the video in a lightbox and stops the music:

<a style="position:relative; font-size:20px; text-decoration:none; top:-109px; left:-65px;" href="http://www.pccmedia.net/other/P25_60sec.mp4" rel="lightbox[set 720 405]" title="Project 25" onClick="stop1()"/> link</a>

At this point everything is working - I just can't get the audio to stop for the popup.

Philip M
01-08-2012, 12:07 PM
I do not see how the script which plays the music is called. Is it with <body onload = >?

But it seems to me that you are going about this the wrong way. The logic is simple enough:-

If the cookie is not found, we assume the visitor is new to the site and hence annoy them by compelling them to watch a video. As you have done.

If the cookie is found, then the visitor is returning so we do not play the video. We annoy them with some music instead.

There is no point in stopping the music which has been started for all visitors.

You seem to have noticed that all modern browsers block unrequested popups. Thank God!!!