View Full Version : getting script to load last

12-14-2007, 04:20 AM
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?


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')==''){


12-14-2007, 05:59 AM
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...

12-14-2007, 06:24 AM
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?

12-14-2007, 10:26 PM
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.