how the linkedin js is a valid javascript

不羁的心 提交于 2019-12-13 12:27:18

问题


LinkedIn Javascript integration is done with:

<script src="http://platform.linkedin.com/in.js" type="text/javascript">
   api_key: 9XXXXXXX
   authorize: true
</script>

What I do not understand, how this is a valid javascript? How come the api_key is not quoted.


回答1:


The body of a script tag with a src is never executed. However, the loaded script can access its contents like the contents of any other element. So it's a nice place to store metadata related to the script that was loaded.

Actually, it was a nice place for it before data- attributes got introduced. Using them would be more appropriate, but the linkedin api is probably older than data- attributes or they simply wanted to keep it simple.

A possible way to access the tag is putting the following code in the .js file:

var scripts = document.getElementsByTagName('script');
var thisScriptTag = scripts[scripts.length - 1];

Source

You can then use the textContent or innerText property to access whatever is in the tag.



来源:https://stackoverflow.com/questions/11336743/how-the-linkedin-js-is-a-valid-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!