嵌入 HTML5 / 带参数的 JS Web App

Embed HTML5 / JS Web App with parameters

我得到了 JSON url 其中 return 一些数据。我需要创建一个 javascript / html5 / css 应用程序来抓取这些数据并 return 它在列表中。

至此,我可以接受了。

我的问题是我需要能够提供 <script></script> 用户可以将其粘贴到任何其他网站以显示网络应用程序。

脚本或 iframe 需要能够获取参数,以便过滤 returned 数据。

任何人都可以按照正确的方向指导我如何操作吗?

最简单的方法是使用全局变量。

编辑: 添加了一种方法来 "embed" 生成的内容。我在示例中使用 jQuery,但可以使用任何其他 DOM 操作库或纯 JS 轻松完成。

最终用户添加带有特定 id 的 HTML 元素和包含参数的 <script> 标签。我们在示例中使用 div 元素。

<div id="generated-list"></div>
<script>
    // the user defines parameters
    var configParameters = {param1: 'some value', param2: ['is', 'array']};
</script>

最终用户应粘贴您的代码。我不知道你的代码怎么样,所以我做了这个:

<script>
    // The user pastes your script here
    // which may be a function accepting the defined parameters
    function createList(configParameters) {
        // create the necessary elements and append them to the element
        // with the right id
        // We create an empty ul element in the example
        var newList = $('<ul></ul>');
        $('#generated-list').append(newList);
    }
</script>

Google 分析使用类似的方法