开发者

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:

  • A selector to use to find the place you would like to insert the loaded page.
  • A folder path to use at the document root. (Think Apache configuration)
  • The page to load if there isn't a hash tag.

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 f开发者_如何学编程or 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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜