Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please explain this example script from the LinkedIn developer API

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:

  1. What is the type and scope of the api_key object?
  2. 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.

like image 403
Michiel van Oosterhout Avatar asked Oct 10 '22 08:10

Michiel van Oosterhout


1 Answers

What is the type and scope of the api_key object?

If you treat this as JavaScript then…

It is a label followed by a (presumably) undefined variable, which will throw a reference error.

Does the referred script have special access to the content in the script tag because its the src of the tag?

No. The content of the script element is the fallback for when src is 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 their innerHTML.

like image 78
Quentin Avatar answered Oct 20 '22 04:10

Quentin