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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getting script to load last

    Hi everyone

    just so you know i know nothing of coding but i have managed to find a script to do what i want but what i was wondering could someone pls show me how to make it load last?

    Code:
    <script>
    
    function playmusic(){
    document.write('<embed src="http://www.mydomain.com/ipb/sounds/1_to_use.mp3" autostart="true" hidden="true" loop="false"></embed>');
    }
    
    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
    offset += search.length
    // set index of beginning of value
    end = document.cookie.indexOf(";", offset);
    // set index of end of cookie value
    if (end == -1)
    end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }
    
    function playornot(){
    if (get_cookie('playedonce')==''){
    playmusic()
    document.cookie="playedonce=yes"
    }
    }
    
    playornot()
    </script>

  • #2
    New Coder
    Join Date
    Jun 2005
    Posts
    52
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Not the best way of doing this, but you can quickly get away with...

    window.onload = function () { playornot(); }

    If that's what you're asking for...

  • #3
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how would you suggest i go about it then?

    basically what i want it to do is play the mp3 per session?... so that ppl first go to the site the file will play and then not again unless they came back at another time?
    Last edited by 2greedy; 12-14-2007 at 05:27 AM.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,620
    Thanks
    0
    Thanked 645 Times in 635 Posts
    You will have to get rid of the document.write if you want to load it last. If you follow Zefris' suggestion then it will overwrite the entire page when it loads last.

    I would get rid of the proprietary embed tag too as all browsers support the standard object tag for embedding files. You would also probably do better to link to the file rather than annoying your visitors by interrupting their background music or getting them fi9red from their job by blasting out your sound without their first asking to listen to it.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    LinkBacks (?)


    Posting Permissions

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