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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Random Music loader/refresh

    This is a script that will load a page with a random background song, plus will refresh the page when the song finishes!

    Code:
    <script language="javascript">
    // use this script freely
    // var numsong stands for the number of songs given
    var nummidi = 5
    day = new Date()
    seed = day.getTime()
    ran = parseInt(((seed - (parseInt(seed/1000,10) * 1000))/10)/100*numsong
    + 1,10)
    if (ran == (5))
    {
    song=("song source")
    words=("song name")
    time=("song time in seconds")
    }
    else if (ran == (4))
    {
    song=("song source")
    words=("song name")
    time=("song time in seconds")
    }
    else if (ran == (3))
    {
    song=("song source")
    words=("song name")
    time=("song time in seconds")
    }
    else if (ran == (2))
    {
    song=("song source")
    words=("song name")
    time=("song time in seconds")
    }
    else if (ran == (1))
    {
    song=("song source")
    words=("song name")
    time=("song time in seconds")
    }
    document.write('<meta http-equiv="refresh" content="' + time + '; URL=npmusic.html">') 
    document.write('<EMBED SRC= "' + song + '" CONTROLS=smallconsole HEIGHT=45 WIDTH=290 AUTOSTART=TRUE LOOP=FALSE VOLUME=100%>')
    document.write('<br>You are listening to ' + words + ' ')
    </SCRIPT>
    This script was made for a small pop-up window to have nothing but the song file in it. Also, you use this script in the <body> of the file. (Yes, the meta tag works there)

    Hope someone can make use of it

  • #2
    New Coder
    Join Date
    Jun 2002
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb

    Very creative!!! 5/5 stars!

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I noticed a small error... where it says nummidi, that is supposed to be numsongs... in case you couldn't figure out yourself

  • #4
    New Coder
    Join Date
    Jun 2002
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Didn't even notice it. I just read the main parts of the code, like the meta tag. And how you wrote out the song title. That mistake doesn't cost you a star, so it's still 5/5

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am not fully deserving of such praise. I did not make the main part of the code:

    Code:
    var numsong = 5
    day = new Date()
    seed = day.getTime()
    ran = parseInt(((seed - (parseInt(seed/1000,10) * 1000))/10)/100*numsong
    + 1,10)
    I in fact got an origional layout and well, added the auto refresh and cleaned up the if-else statements... (If I left them the way the code origionally was, there would be 15 if statments )

    So, I give out praise to whoever made up the origional code!!!

  • #6
    New Coder
    Join Date
    Jun 2002
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's still a lot more than I can do. I can only cut and paste. I can only make minor edits to JavaScripts, like when I see a document.write. I wouldn't have thought up using variables and stuff. I think I could learn how, but JavaScript isn't really important to me.

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have found something out.... If you refresh the page manually, without letting the script run alone, it will not do the refresh anymore... The only way to get the script running again, would be to close, then re-open the window with the script....

  • #8
    New Coder
    Join Date
    Jun 2002
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Probably needs a "return false" on the keypress event. Or, you could try:

    <body onkeypress="stop()">

    function stop(){return false;}

    Syntax might not be right, but the above is what I think is right...sigh I'm sure I'll learn it sooner or later

    <edit my="post">I thought I'd debut a new signature. It's funny :-)</edit>
    Last edited by jscript_junkie; 07-22-2002 at 06:34 AM.


  •  

    Posting Permissions

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