给我一个返回一些数据的JSON url。我需要创建一个javascript / html5 / css应用程序,该应用程序将提取此数据并将其返回到列表中。
到目前为止,我可以这样做。
我的问题是,然后我需要能够提供一个<script></script>
可供用户粘贴到任何其他网站中以显示该Web应用程序的工具。
脚本或iframe需要能够获取参数,以便可以过滤返回的数据。
谁能在正确的方向上指导我有关如何执行此操作的说明?
最简单的方法是使用全局变量。
编辑:添加了一种“嵌入”生成内容的方法。我在示例中使用jQuery,但是可以使用任何其他DOM操作库或纯JS轻松完成。
最终用户添加带有特定元素的HTML元素id
和<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 Analytics(分析)使用类似的方法
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句