https://github.com/gera2ld/fallback-js
Set up fallback messages easily
https://github.com/gera2ld/fallback-js
Last synced: about 2 months ago
JSON representation
Set up fallback messages easily
- Host: GitHub
- URL: https://github.com/gera2ld/fallback-js
- Owner: gera2ld
- Created: 2018-04-15T08:21:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-10T04:44:52.000Z (about 7 years ago)
- Last Synced: 2026-05-12T00:32:35.718Z (2 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
@gera2ld/fallback-js
---


Set up fallback messages easily when browser fails running essential scripts.
### Why
In case you have an application targeting the latest browsers, you may need to notify users to upgrade their browsers if they are using an obsolete one.
With this script you can easily set up a notice when essential scripts fail.
### Basic Usage
1. Add necessary elements
```html
This is the main application.
Oops
Unfortunately, your browser is too old to work for this application. Please upgrade your browser.
```
2. Be sure to call `FallbackJs.ok()` after your main script (`app.js` here).
```js
// app.js
// ...
// call ok at the end
FallbackJs.ok();
```
### Advanced Usage
Configurations can be overridden by assigning to `window._fallbackJs` before running `fallback-js`.
```html
window._fallbackJs = {
debug: true,
onError: function (errors) {
console.error(errors);
},
};
```
Available configurations are:
- debug: *boolean*, default as `false`
Whether to show debug messages.
- selector: *string*, default as `'#fallback-js'`
If an element is found by `document.querySelector(selector)`, it will be shown when essential scripts fail.
- timeout: *number*, default as `1000`
Time to wait until `FallbackJs.ok()` is called.
- count: *number*, default as `1`
The number of scripts that are supposed to run successfully and call `FallbackJs.ok()`.
- hide: *string*, default as `null`
If specified and an element is found by `document.querySelector(hide)`, it will be hidden once scripts fail.
- onError: *function*, default as `null`
Once scripts fail, errors will be passed to this callback. It is useful if you want to show the error details.