https://github.com/farhadg/script-tag-data
:paperclip: Set and read data from a JavaScript <script> tag
https://github.com/farhadg/script-tag-data
script script-data
Last synced: 10 months ago
JSON representation
:paperclip: Set and read data from a JavaScript <script> tag
- Host: GitHub
- URL: https://github.com/farhadg/script-tag-data
- Owner: FarhadG
- Created: 2015-11-23T07:49:13.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-27T19:35:34.000Z (about 10 years ago)
- Last Synced: 2025-03-02T19:06:03.309Z (11 months ago)
- Topics: script, script-data
- Language: JavaScript
- Homepage: http://farhadg.github.io/script-tag-data/
- Size: 31.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Script Tag Data
=======================================================================================
Set and read data from a `` tag. You can check this out being used in my <a href="https://www.github.com/farhadg/repo-card" target="_blank">Repo Card</a> project.
### Installation
Bower
```bash
$ bower install script-tag-data --save
```
CDN
```html
<script src="https://rawgit.com/FarhadG/script-tag-data/master/script-tag-data.min.js">
```
### Usage
```html
```
Provide the user / app a simple `` tag, a CSS `#id` and whatever data points as HTML5 `data` attributes.
- Get all of the data values from a `<script>` tag: `ScriptTagData.getData(scriptId)`
- Only get the `<script>` tag: `ScriptTagData.getScript(scriptId)`
### Examples
Some website with your `<script>` tag, an ID and the desired data points.
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
...
<script id="your-library" src="./your-library.js" data-car="pagani" data-star-repo="yes, please :)">
</body>
</html>
```
Your JS file where you have ScriptTagData library loaded by either referencing from here on <a href="https://cdn.rawgit.com/FarhadG/script-tag-data/master/script-tag-data.min.js" target="_blank">GitHub</a> or serving it yourself.
```javascript
/**
* This returns the following:
*
* {
* car: 'pagani',
* starRepo: 'yes, please :)'
* }
*/
ScriptTagData.getData('your-library');
/**
* This returns the just <script> tag
*/
ScriptTagData.getData('your-library');
```
### Questions
Please use issues page for any questions or concerns.