Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need to Stop Music Playing for New Visitors

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    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.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by ohmitmedia View Post
    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.

    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.
    Last edited by Philip M; 01-07-2012 at 06:40 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New Coder
    Join Date
    Oct 2011
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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:
    Code:
    <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",
    "width=894,height=540,scrollbars=yes,menubar=no");
    expire=new Date(expire.getTime()+7776000000);
    document.cookie="COOKIE1=here; expires="+expire;
    
    }
    // --> 
    </script>
    Here is the audio script in the head
    Code:
    <script language="javascript">
    function getPlayer(movieName)
    	{
    		if (navigator.appName.indexOf("Microsoft") != -1) 
    		{
    			return window[movieName];
            	} 
    		else 
    		{
    			return document[movieName];
            	}
         	}	
    	
    	function stop1()
            {
                    getPlayer("player1").stopMusic();
            }
    </script>

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

    Code:
    <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.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    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!!!
    Last edited by Philip M; 01-08-2012 at 11:10 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •