谷歌+1 javascript配置对象 [英] google +1 javascript configuration object

查看:85
本文介绍了谷歌+1 javascript配置对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

google +1按钮嵌入代码可以包含配置的javascript对象(例如 {lang:'de'} )。

The google +1 button embed code can have a javascript object with configuration (e.g. "{lang:'de'}").

在普通的javascript中,这个对象会被创建并立即销毁,因为它没有被任何东西引用。

In plain javascript, this object would be created and immediately destroyed, because it is not referenced by anything.

我想知道谷歌是怎么做的脚本访问此对象?

I wonder how do the google scripts access this object?

<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
  {lang: 'de'}
</script>

它似乎有效 - 除非您将包含配置对象的脚本标记动态写入DOM。

It seems to work - except when you dynamically write the script tag including the configuration object into the DOM.

推荐答案

Widget脚本在document.scripts上运行,并在scr属性中搜索字符串/js/plusone.js。
在此修剪字符串之后并创建匿名函数。
结果是具有配置属性的对象。

Widget script run at document.scripts and searching one with string "/js/plusone.js" in scr attribute. After this trim string and create anonymous function. Result of it is object with configuration properties.

if (Gb[u] > 0) {
    for (var Hb = "", Ib = 0; Ib < Gb[u]; Ib++) {
        var Jb = Gb[Ib][nb]("src");
        Jb && Jb[q]("/js/plusone.js") != -1 && (Hb = Q.d.rb(Gb[Ib]));
    }
    Hb = Hb[Ea](/^\s+|\s+$/g, "");
    Hb[q]("{") != 0 && (Hb = "{" + Hb + "}");
    try {
        var Kb = (new Function("return (" + Hb + "\n)"))(), Mb;
        for (Mb in Kb) i.__GOOGLEAPIS.gwidget[Mb] = Kb[Mb];
    } catch (Nb) {}
}

这篇关于谷歌+1 javascript配置对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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