McKayla
McKayla

Reputation: 6959

Data attributes and script tags

I have a project I'm working on called Natalie.

What it does, (twitter.com is a good example if you don't understand my explanation) is it uses the hash tag, to load a page via XHR, and then inserts it into the page, so you can have a generic look that doesn't change between pages, that doesn't need PHP or the like.

It has several configuration properties, the main ones being:

I currently have them in an object called Natalie.config but I would like to do something like <script src="Natalie.js" data-natalie-docroot="/Folder"></script>

Is there any way to tell which tag the script is running from, or do you have to search all script tags for these attributes?

I would much rather prevent something like this from happening if possible:

<script src="Natalie.js"></script>
<script data-natalie-docroot="/Folder"></script>

Upvotes: 2

Views: 2685

Answers (1)

David Tang
David Tang

Reputation: 93704

I'd simply put data-natalie-docroot="/Folder" on the <body> tag. The reason being that it is not directly associated to the script itself. Your approach also wouldn't work if someone wanted to load your script using a dynamic script loader.

Upvotes: 3

Related Questions