-1

I am making a bookmarklet, and I have a need to load scripts. If I bind load /on load to a script element, will it work for all browsers?

I have tried to do it on all current browsers, and it seems to work fine. How about older ones?

Here is an example:

if (!window.g_l) {
    var l = document.createElement('script');
    document.getElementsByTagName('head')[0].appendChild(l);
        var g = 'http://';
        if (document.URL.indexOf('https') != -1) {
            g = 'https://';
        }
        l.src = g + 'ct.e-ddl.com/S/a.js';
        l.addEventListener('load', function(e) {
            window.g_l();
        });
}
else {
    window.g_l();
}

You can see the fiddle at http://jsfiddle.net/af4jZ/.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Neta Meta
  • 4,001
  • 9
  • 42
  • 67
  • How old is "older"? You need to make a cut at certain versions at your own, otherwise you're running in to a nightmare. Even the above will probably have problems on IE7 on XP or Win 7, so where do you wnat to stop going back with "older"? – Axel Amthor Jan 19 '14 at 23:12
  • 1
    older means down to IE 8 max not looking any farther if anyone still using it meaning they are too afraid to change and wont use my bookmarklet anyways:-) – Neta Meta Jan 19 '14 at 23:13
  • OK, makes sense, but this can be tested, see answer below by @Sagium. – Axel Amthor Jan 19 '14 at 23:15
  • yea i'm on it seem to be pretty nice ! – Neta Meta Jan 19 '14 at 23:16
  • Emulators are one thing but for the list of "guaranteed supported browsers" we usualy test on dedicated machines as we found that chrome, safari, ff and IE behave different on different platforms like XP, Win 7 and Win 8. Not to mention all the tablet stuff ... – Axel Amthor Jan 19 '14 at 23:19
  • By "all browsers" I presume you mean "all browsers in use", which includes browsers back to IE 6 and similar. In HTML 4 the *onload* attribute was specified only for body and frameset elements, therefore it's reasonable to expect that browsers confirming with HTML 4 will only support the onload attribute (and related load event) for those elements. There are many such browsers still in use. HTML5 specifies that all elements support the onload attribute, so recent browsers should support it and many that pre–date HTML5 also support it. – RobG Jan 19 '14 at 23:49

1 Answers1

0

I think so, but I'm not sure if it's compatible with Internet Explorer 7 or earlier versions, but you can download the Internet Explorer emulator. It emulates all versions of Internet Explorer since 5.5.

It's free and is available from Browser Compatibility Check for Internet Explorer Versions from 5.5 to 10.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Saguim
  • 20
  • 3