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
5 Answers
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 load
and dom ready
see 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
版权声明:本文标题:jquery - Auto load Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741307712a2371469.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论