0

The method i am trying to use is like this:

  1. A script verifies if the 'CSS3' property is available in the user browser.(transition property)
  2. If it isn't then JavaScript file will be downloaded as fallback (this will do the animations)

My question is :

How can I download a JS file into the users browser? Is this even possible? What other methods do you suggest?

PS: Really new in this domain so please help! Thank you!

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Tbi45
  • 607
  • 2
  • 6
  • 14
  • 1
    http://stackoverflow.com/questions/950087/include-javascript-file-inside-javascript-file – CharliePrynn Dec 19 '12 at 11:16
  • 1
    have you figured out the javascript http://modernizr.com/ ??? – algorhythm Dec 19 '12 at 11:18
  • 1
    @algorhythm +1 for notice modernizr. check out [boilerplate](http://html5boilerplate.com/) for the whole package. – Ron van der Heijden Dec 19 '12 at 11:22
  • Yep. the verification is simple to do because i have to verify only one property so i don't need modernizr tool. And there is a lot of script that is too complicated for me (at least for now) – Tbi45 Dec 19 '12 at 11:51
  • A good (though slightly dated) [introduction to modernizr](http://www.alistapart.com/articles/taking-advantage-of-html5-and-css3-with-modernizr/) – robertc Dec 19 '12 at 11:52

2 Answers2

0

Why downloading a script later? Put the script directly in the head and wrap it in an if-else-clause so that it do nothing, if CSS3 is available...

Otherwise you can change the DOM and place a new script in the head...

algorhythm
  • 8,530
  • 3
  • 35
  • 47
0

This is a very simple implementation that checks for css transition support and, if it does not exist, loads an external JS file:

HTML

 <!-- make sure you include <script> link to to modernizr.js in your <head> before this script -->
    <script>
      // if browser does not support transitions. If not, load in our polyfill
        Modernizr.load({
          test: Modernizr.csstransitions,
          nope: '/js/polyfill.js'
        });// END Modernizr.load
    </script>

Additionally here is a list of polyfills that you can use to reproduce modern functionality in older browsers (be cautious here though, there can be a large performance hit).

Hope that helps!

Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90
  • aha. i guess i'm going to use the Modernizr solution since there are so many users recommending it. – Tbi45 Dec 20 '12 at 09:11
  • I would highly recommend it. It gives you the freedom to use the shiny new stuff without leaving users on older browsers completely out in the cold. – Nick Tomlin Dec 20 '12 at 15:29