Monday, 15 June 2015

javascript - Can you wait to define a function until the onload event? -



javascript - Can you wait to define a function until the onload event? -

first of all, i'm wondering whether or not can utilize window.onload define function without running until <button> clicked.

i have apps have designed in javascript, , of them designed specific sites use, on sites have problem allowing other users alternative utilize apps without making page take forever load of them. can find apps @ http://jsfiddle.net/kaloncpu57/b9wcn/ don't think problem lies within apps (unless can find way condense them downwards nothing).

also, reference, sites i'm having problem on wapka.mobi sites http://3dsflare.wapka.mobi if want head there test solutions (you'll need register).

to allow other users access apps, set external script in signature along <button> run them (i realize how much of security issue allow scripts in signatures, , trust me, gets exploited time). users having issues using devices don't back upwards defer attribute external scripts, , after many attempts solution have left utilize window.onload load function each app after else loads, using window.onload = function... runs function of course.

is possible wait until page loaded define function, or have other solutions? in advance helpful information.

try reading blog how page can load faster

specially part :

for illustration have on <head> tag

<script type="text/javascript" src="myscript1.js"></script> <script type="text/javascript" src="myscript2.js"></script>

change :

<script type="text/javascript" src="fastload.js"></script>

then in fastload.js :

function addjavascript(jsname) { var th = document.getelementsbytagname('head')[0]; var s = document.createelement('script'); s.setattribute('type','text/javascript'); s.setattribute('src',jsname); th.appendchild(s); } addjavascript('myscript1.js'); addjavascript('myscript2.js');

hope help you.

javascript load onload

No comments:

Post a Comment