Jump to content

Recommended Posts

i have no clue in javascript

im trying to avoid the operation abort problems  that arise

when using the lightbox jquery files.

i have read a bit and this is the solution i cam up with

but the files wont load

// JavaScript Document
<script type="text/javascript">
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

addLoadEvent(function() {
    document.write('<object type="text/javascript" src="js/prototype.js" ></object>');
})type="text/javascript" src="js/prototype.js"
})
addLoadEvent(function() {
    document.write('<object type=" text/javascript"  src="js/scriptaculous.js?load=effects,builder" ></object>');
})
addLoadEvent(function() {
document.write('<object type="text/javascript" src="js/lightbox.js" ></object>');
})
</script>

Link to comment
https://forums.phpfreaks.com/topic/167516-onload-javascript-help/
Share on other sites

i have no clue in javascript

im trying to avoid the operation abort problems  that arise

when using the lightbox jquery files.

i have read a bit and this is the solution i cam up with

but the files wont load

// JavaScript Document
<script type="text/javascript">
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

addLoadEvent(function() {
    document.write('<object type="text/javascript" src="js/prototype.js" ></object>');
})type="text/javascript" src="js/prototype.js"
})
addLoadEvent(function() {
    document.write('<object type=" text/javascript"  src="js/scriptaculous.js?load=effects,builder" ></object>');
})
addLoadEvent(function() {
document.write('<object type="text/javascript" src="js/lightbox.js" ></object>');
})
</script>

 

What is it exactly that you're trying to do?

im trying to load the js files when the browser

finished loading the whole page

 

there is an error in all ie up to ie7

 

apparently the solution is to get these files

load after the browser gets to  the </body> tag

**the lightbox script lets you show an

image gallery using jquery

 

im trying to call the files using the onload function

im trying to load the js files when the browser

finished loading the whole page

 

there is an error in all ie up to ie7

 

apparently the solution is to get these files

load after the browser gets to  the </body> tag

**the lightbox script lets you show an

image gallery using jquery

 

im trying to call the files using the onload function

 

Why not try something like:

 

<script type="text/javascript">
   window.onload = function(){
      var documentHead = document.getElementsByTagName('head')[0];

      var protoScript = document.createElement('script');
      var scriptaculousScript = document.createElement('script');
      var lightboxScript = document.createElement('script');

      protoScript.type = 'text/javascript';
      protoScript.src = 'js/prototype.js';

      scriptaculousScript.type = 'text/javascript';
      scriptaculousScript.src = 'js/scriptaculous.js?load=effects,builder';

      lightboxScript.type = 'text/javascript';
      lightboxScript.src = 'js/lightbox.js';

      documentHead.appendChild(protoScript);
      documentHead.appendChild(scriptaculousScript);
      documentHead.appendChild(lightboxScript);
   }
</script>

If jquery is done properly, it won't load in any browser until it is ready to be loaded. Most people who know how to use jquery know how to do this, so you may have an entirely different problem.

 

the original script without the onload function works fine

this is a known problem in ie apparently and their fix is to update to ie8 ;)

im trying to load the js files when the browser

finished loading the whole page

 

there is an error in all ie up to ie7

 

apparently the solution is to get these files

load after the browser gets to  the </body> tag

**the lightbox script lets you show an

image gallery using jquery

 

im trying to call the files using the onload function

 

Why not try something like:

 

<script type="text/javascript">
   window.onload = function(){
      var documentHead = document.getElementsByTagName('head')[0];

      var protoScript = document.createElement('script');
      var scriptaculousScript = document.createElement('script');
      var lightboxScript = document.createElement('script');

      protoScript.type = 'text/javascript';
      protoScript.src = 'js/prototype.js';

      scriptaculousScript.type = 'text/javascript';
      scriptaculousScript.src = 'js/scriptaculous.js?load=effects,builder';

      lightboxScript.type = 'text/javascript';
      lightboxScript.src = 'js/lightbox.js';

      documentHead.appendChild(protoScript);
      documentHead.appendChild(scriptaculousScript);
      documentHead.appendChild(lightboxScript);
   }
</script>

 

it loads for ever now

i placed it after the </body> tag

Don't place what I wrote after the body tag.  Put it in the head, where most scripts are supposed to go.

 

Really, if you're going to attempt using JavaScript, you should at least know where to place your scripts.

sorry i was in the former solution state of mind.

 

it now doesn't work on firefox and ie

the scripts arent loaded

 

Without reading through all that code which doesn't seem necessary at all. I see you meantion jQuery and in the script I see prototype and scriptaculous mentioned. Could it be that these just conflict?

 

If so I suggest you just stick with either prototype.js or jQuery. If you absolutely have to use both (can't imagine why). Then take a look at jquery's noconflict mode.

Put it in the head, where most scripts are supposed to go.

 

That's actually not correct. Scripts can go anywhere, and often it's beneficial to put them at the end of the document, or at least after the element they apply to. A very visible example of this is google analytics, which is placed as the last element in the document.

Put it in the head, where most scripts are supposed to go.

 

That's actually not correct. Scripts can go anywhere, and often it's beneficial to put them at the end of the document, or at least after the element they apply to. A very visible example of this is google analytics, which is placed as the last element in the document.

 

I'm surprised they don't just use an in-house version of $(document).ready() to do that.

 

Still, in most cases, from what I've seen/read, convention seems to be that scripts should go in the head, to be executed after window.onload, or the previously mentioned ready() function.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.