Domanda

I saw this on the LinkedIn developer docs:

<script type="text/javascript" src="http://platform.linkedin.com/in.js">
  api_key:    [API_KEY]
  onLoad:     [ONLOAD]
  authorize:  [AUTHORIZE]
</script>

Is this valid JavaScript syntax? I understand that colon is normally used to set the properties of an object, so I'm a bit confused with this example using it without the context of an object.

È stato utile?

Soluzione

The contents of the script tag won't actually be treated as JavaScript because the <script> tag has a src attribute. The script that you're loading iterates through all of the <script> tags, sees if any of them are loading platform.linkedin.com/in.js, and then parses the body of the tags with JavaScript.

This is actually invalid HTML and really unintuitive, so don't do it. If a script tag has a src attribute, it must either be completely empty or contain just JavaScript comments (source), so it isn't a good idea to rely on lenient browser behavior.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top