linkedin js如何是有效的javascript [英] how the linkedin js is a valid javascript

查看:75
本文介绍了linkedin js如何是有效的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LinkedIn Javascript集成是通过以下方式完成的:

LinkedIn Javascript integration is done with:

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

我不明白,这是有效的JavaScript吗? api_key为何不加引号.

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

推荐答案

永远不会执行带有src的脚本标记的主体.但是,加载的脚本可以像访问其他任何元素的内容一样访问其内容.因此,这是一个存储与所加载脚本相关的元数据的好地方.

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.

实际上,在引入data-属性之前,它是一个不错的地方.使用它们会更合适,但是linkedin API可能早于data-属性,或者他们只是想保持简单.

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.

一种访问标记的可能方法是将以下代码放入.js文件中:

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];

来源

然后您可以使用textContentinnerText属性访问标记中的内容.

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

这篇关于linkedin js如何是有效的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆