Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

window.onload = function()


I have searched, read, and tried multiple variations, all with no luck. I Can't use the onLoad in the <body> tag so I have to use the window.onload. Code attached below, if the function is called in the body tag it all works fine. If I try the other way nothing comes up. I'm sure its a simple issue I'm overlooking and thats why I'm here...

<
<head>

<script type="text/javascript" src="/Scripts/swfobject-2.1.js"></script>
<script type="text/javascript">
// <![CDATA[


function createPlayer(theFile) {
var flashvars = {
file:theFile,
autostart:"true",
playlistsize:"250",
playlist:"bottom"
}
var params = {
allowfullscreen:"true",
allowscriptaccess:"always"
}
var attributes = {
id:"player1",
name:"player1"
}
swfobject.embedSWF("/video/player.swf", "placeholder1", "640", "600", "9.0.115", true, flashvars, params, attributes);


}

// ]]>

window.onload = function() { createplayer('/video/mrss_euphoriaSpeakers.xml'); }

</script>


</head>

<!--<body onload="createPlayer('/video/mrss_euphoriaSpeakers.xml')"> -->
<body>

<div id="wrapper">
<div id="placeholder1"></div>
</div>


</body>
</html>

>

4 Community Answers

JW Player

User  
0 rated :

just to add...Using the many examples and precoded setups here are great. I can get 90% of them to work with simple copy-n-paste. BUT thats using the <body onLoad> tag. So its some sort of stupid mistake i'm makeing with the window.onload = function() { createplayer('/video/mrss_euphoriaSpeakers.xml'); } function. probably a " of ; in the wrong place or maybe its insided the } <script> when it should be outside it.

I've tried several dozen combinations and I know I just have to be overlooking something simple. A fresh set of eyes from the outside can probably help with little trouble.

Thank you in advance.
Thomas

JW Player

User  
0 rated :

Excellent, both options worked fine. I appreciate the effort. If I can repay that with any trade of service just holler.

For anyone searching similar topics later, I am posting the working code here. Everything works great, just replace the variables with your own xml files and locations and you should be good to go.

bc.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Media Player</title>

<script type="text/javascript" src="/Scripts/swfobject-2.1.js"></script>
<script type="text/javascript">
// <![CDATA[

function createPlayer(theFile) {
var flashvars = {
file:"/video/mrss_euphoriaSpeakers.xml",
autostart:"true",
playlistsize:"250",
playlist:"bottom"
};
var params = {
allowfullscreen:"true",
allowscriptaccess:"always"
};
var attributes = {
id:"player1",
name:"player1"
};
swfobject.embedSWF("/video/player.swf", "placeholder1", "640", "600", "9.0.115", true, flashvars, params, attributes);

// ]]>
};

<!-- window.onload = function() { createPlayer('/video/mrss_euphoriaSpeakers.xml'); } //works correctly - code from Anderson http://www.jeroenwijering.com/?thread=14332#msg97345 -->

function init() { createPlayer('/video/mrss_euphoriaSpeakers.xml'); } // works correctly - from Anderson http://www.jeroenwijering.com/?thread=14332#msg97345 -- use this line + line below
window.onload = init; //from Anderson http://www.jeroenwijering.com/?thread=14332#msg97345 -- use this line + line above

</script>
</head>

<!--<body onload="createPlayer('/video/mrss_euphoriaSpeakers.xml')"> //works correctly if you want or need the player loaded in the body tag -->
<!--<body onload="createPlayer()"> //works correctly if you want or need the player loaded in the body tag -->
<body>

<div id="wrapper">
<div id="placeholder1"></div>
</div>

</body>
</html>

JW Player

User  
0 rated :

Is it possible to call createPlayer inside body tag? I've tried everything but could not figure it out...

JW Player

User  
0 rated :

bc.. function init() { createPlayer('/video/mrss_euphoriaSpeakers.xml'); }

window.onload = init;
or bc.. window.onload = function() { createPlayer('/video/mrss_euphoriaSpeakers.xml'); }

This question has received the maximum number of answers.