I’m just getting started with the LinkedIn JavaScript API and right away I noticed a pattern that I am not familiar with:
<script src="http://platform.linkedin.com/in.js">
api_key: dfghyu8v2tg
</script>
I have two questions:
- What is the type and scope of the api_key object?
- Does the referred script have special access to the content in the script tag because its the src of the tag?
Edit:
According to Douglas Crockford (emphasis mine):
The src attribute is optional. If it is present, then its value is a
url which identifies a .js file. The loading and processing of the
page pauses while the browser fetches, compiles, and executes the
file. The content between the<script src="url">and the</script>
should be blank.If the src attribute is not present, then the content text between the
<script>and the</script>is compiled and executed.
It seems to me that the LinkedIn example does not meet these requirements.
If you treat this as JavaScript then…
It is a label followed by a (presumably) undefined variable, which will throw a reference error.
No. The content of the script element is the fallback for when
srcis not supported. It is being abused as a hack to include extra data. A glance at the script (in the src) suggests it loops over all the<script>elements it can find and checks theirinnerHTML.