4

I'm building a script (and HTML) that people can embed in their website that adds a form to join our application.

I want to design it using bootstrap but i'm afraid of conflicts.

I know i can check if bootstrap is loaded using:

typeof $().modal == 'function'

Is there a way to check the version of bootstrap that is currently loaded?

I was thinking of the following algorithm for building the form:

No bootstrap => load bootstrap and bootstrap HTML

Bootstrap version 3.x => load bootstrap HTML

Bootstrap version other than 3.x => load regular HTML form

If there's no way of checking the version (maybe using "v3.x only" functions), i would appreciate other ideas

Thanks

Nim
  • 99
  • 5
  • Irritatingly, I'm not seeing this put anywhere on purpose in the [distribution file](https://github.com/twbs/bootstrap/blob/master/dist/js/bootstrap.js). That means having to sniff... :-( – T.J. Crowder Jan 02 '14 at 11:27
  • what are the issue you are expecting? Could you not use a polly filler to solve issues etc? – Simon Davies Jan 02 '14 at 11:36
  • 7
    Loading something _huge_ like bootstrap (and/or jQuery) for a script people embed on their site - taking hundreds of miliseconds is extremely bad user experience. You'll be slowing people's sites down a lot by doing this. Consider not using bootstrap for this sort of thing. – Benjamin Gruenbaum Jan 02 '14 at 11:36
  • @SimonDavies in different versions of bootstrap you use different classes (at least between version 2 and 3) i'm not sure what a "polly filler" is. but i think i will use a different way to implement the add-on. thank everyone for the quick replies – Nim Jan 02 '14 at 20:48
  • @user3129985 not a problem, a poly filler though is js code etc that compensates for older browsers and adds or mimics the latest browser elements. take a look at http://html5boilerplate.com/ for eg – Simon Davies Jan 03 '14 at 09:30

1 Answers1

0

As suggested in this question, you could check for the existence of a function which is introduced / removed in Bootstrap 3 and vice versa. One function that seems to be removed from Bootstrap 3 is the typeahead method.

Another suggestion is to load the CSS file (either via an AJAX request, or by directly tapping into the loaded stylesheets in the DOM?) and interpreting the comment on top of the file.

Both methods are not exactly pretty though.

Community
  • 1
  • 1