开发者

$.getScript, possible to give included script an id?

Via jquery's $.getScript method, can you give the included script a DOM id?

So generated code should be:

<script type="text/javascript" id="xxxxxx" src="..."></script>

I know I could probably just document.write that line myself, but $.getScript must be there for a reaso开发者_开发技巧n right? (cross browser compatibility, etc?)


I think this has maybe been answered/discussed before here: Why call $.getScript instead of using the <script> tag directly?.

getScript allows you to dynamically load a script in situations where it's either desirable to delay the loading of the script, in situations where you want to get a status callback on when the script has been loaded or in situations where you couldn't use a script tag.

getScript has some downsides in that it's subject to the same-origin policy whereas a script tag is not.

If have seen other web pages put an ID on a script tag (smugmug.com), but I've also seen that flagged as non-standard when testing standard's compliance. It seems to work and be used by others, but I'm guessing it isn't standard.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜