admin管理员组

文章数量:1287290

I have a flash games website. When I enter a game I have a button labeled "Play Game". The user needs to push this button to start the game. But I don't want users to have to start the game by using a button. How and what can I change? Here is the javascript from my website.

}
function sgame() {
var x=document.getElementById('gamefirst').style;
var y=document.getElementById('gamesecond').style;
if(x.display=='block') { x.display='none'; y.display='block'; }
else { x.display='block'; y.display='none'; }
}

and maybe

function swf(src, width, height) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=".cab#version=7,0,19,0" width="733" height="550"  id="currentGame">');
    document.write('<param name="movie" value="' + src + '">');
    document.write('<param name="quality" value="high">');
    document.write('<embed src="' + src + '" id="currentEmbedGame" quality="high" pluginspage=".cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="733" height="550" menu="0"></embed>');
    document.write('</object>');

I have a flash games website. When I enter a game I have a button labeled "Play Game". The user needs to push this button to start the game. But I don't want users to have to start the game by using a button. How and what can I change? Here is the javascript from my website.

}
function sgame() {
var x=document.getElementById('gamefirst').style;
var y=document.getElementById('gamesecond').style;
if(x.display=='block') { x.display='none'; y.display='block'; }
else { x.display='block'; y.display='none'; }
}

and maybe

function swf(src, width, height) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia./pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="733" height="550"  id="currentGame">');
    document.write('<param name="movie" value="' + src + '">');
    document.write('<param name="quality" value="high">');
    document.write('<embed src="' + src + '" id="currentEmbedGame" quality="high" pluginspage="http://www.macromedia./shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="733" height="550" menu="0"></embed>');
    document.write('</object>');
Share Improve this question edited Jun 24, 2014 at 20:57 Lightness Races in Orbit 385k77 gold badges666 silver badges1.1k bronze badges asked Jun 24, 2014 at 20:51 user3771854user3771854 971 gold badge1 silver badge6 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 2
<script type="text/javascript">
    window.onload = function(event) {
        // your code here
    };

    // equivalent with jQuery (when window loads)

    jQuery(window).load(function(event) {
        // your code here
    });

    // alternatively with jQuery (when DOM is ready)

    jQuery(document).ready(function(event) {
        // your code here
    });

    // you can also call a function if this <script>-block is reached (loaded) first time
    // place the <script>-block before body-tag is closing and you have nearly what DOM-ready does.
    someFunction();
</script>

For the difference between window loadand dom readysee here: window.onload vs $(document).ready()

For short: window.onload es later after dom is ready an e.g. all images are loaded.

In your HTML you can try:

<body onload="startgame();">

Or in your JS file you can try:

window.onload=function(){//whatever you need to do;}

Load a function after your body loads, like so:

<body onload="startgame();">

Then create the function

function startgame() {
    alert('Body has loaded!');
}

What about an on load function?

Jquery: JQuery(document).ready(your function here)

JavaScript: window.onload = your function here

Try the following, it's a piece of code that's executed on script load:

(
   function h(){ alert('H'); }
)();

This is useful if you already have a window.onload function.

本文标签: jqueryAuto load JavascriptStack Overflow