简体   繁体   English

关于javascript嵌入代码的新手问题?

[英]newbie question about javascript embed code?

I am a javascript newbie. 我是一个javascript新手。 I am trying to write a requirements document, and need some help describing what I am looking for. 我正在尝试编写一份需求文档,需要一些帮助来描述我在寻找什么。 We want our application to generate a javascript snippet like this: 我们希望我们的应用程序生成如下的javascript代码段:

<script src="http://www.jotform.com/jsform/10511502633"></script> 

This will load a web form. 这将加载Web表单。

So my question is: - How does a single script load an entire web form? 所以我的问题是: - 单个脚本如何加载整个Web表单? Is this a JSON? 这是JSON吗? - What is this called? - 这个叫什么? Is this a cross browser javascript? 这是一个跨浏览器的JavaScript吗? - Can anyone point me in the direction of learning more about what this is? - 有人能指出我更多地了解这是什么吗?

Thank you for your help! 谢谢您的帮助!

The javascript file is just hosted on an external site . javascript文件只托管在外部网站上 It appears to be dynamically generated, so feel free to use some fancy words ;) But basically, you just include it here, as if it was on your own site. 它似乎是动态生成的,所以请随意使用一些花哨的单词;)但基本上,你只需包含在这里,就像它在你自己的网站上一样。

You could say " The application will generate the required script-tags to include dynamically generated javascript file from an external, third-party site ". 您可以说“ 应用程序将生成所需的脚本标记,以包含来自外部第三方网站的动态生成的javascript文件 ”。

Offcourse you need to take special cautions for cases when the include won't work, because the other site is not reachable (site is down, DNS does not work, file is moved on other webserver, your application is on an intranet/behind a proxy/firewall...). 如果包含不起作用,您需要特别注意 ,因为其他网站无法访问(网站已关闭,DNS无效,文件在其他网络服务器上移动,您的应用程序位于内部网/后面代理/防火墙......)。 Why can't you copy their file and mirror it locally ? 为什么你不能复制他们的文件并在本地镜像 Or use a reliable Content Delivery Network, like Google or Amazon. 或使用可靠的内容分发网络,如Google或Amazon。

There are many names for this type of inclusion. 这种类型的包含有很多名称。 The most common being widget . 最常见的是小部件
What does it actually do: 它实际上做了什么:

  • take an id of some sort as parameter 把某种id作为参数
  • use the id to fetch some specific data (most likely from a database) 使用id获取一些特定数据(最有可能来自数据库)
  • generate some js and html based on the id/data 根据id / data生成一些js和html
  • usually this involves iframes of some sort. 通常这涉及某种类型的iframe。

To use a script rather than an html iframe has multiple advantages 使用脚本而不是html iframe有多个优点

  • you can change what is actually delivered to the users browsers without changing the include 您可以在不更改包含的情况下更改实际传送给用户浏览器的内容
  • you can resize the iframe to fit certain predefined sizes 您可以调整iframe的大小以适合某些预定义的大小
  • you can inject the necessary things into the page the widget is included (of course you need to make sure this is sanctioned) 你可以将必要的东西注入到包含小部件的页面中(当然你需要确保这个被批准)

We use this all the time and we never regreted it. 我们一直使用这个,我们从来没有后悔过。

If you don't want to build the widget infrastructure yourself you can always use one of the widget providers like widgetbox: http://www.widgetbox.com/widgets/make/ 如果您不想自己构建窗口小部件基础结构,则可以始终使用其中一个窗口小部件提供程序,例如widgetbox: http//www.widgetbox.com/widgets/make/

With those you are up and running in no time. 随着那些你立即开始运行。

这通常称为脚本包含。

Google have lots of these types of items, and even they call them by many names, widgets, custom javascript, snippets, custom code, etc. It really depending on who you are writing for... I would go with "cross platform embeddable javascript code" meaning that it would need to load all its dependancies. 谷歌有很多这些类型的项目,甚至他们通过许多名称,小部件,自定义javascript,代码片段,自定义代码等来调用它们。这真的取决于你为谁写的...我会选择“跨平台嵌入” javascript代码“意味着它需要加载其所有依赖项。 Also specify which browsers need to be supported and what should happen is the user has javascript turned off. 还要指定需要支持哪些浏览器,以及用户是否关闭了javascript。

EDIT : 编辑:

Actually since we are talking unique IDs, you will need 2 parts probably, the user/site unique "cross platform embeddable javascript code" and whatever serverside code to support it. 实际上,由于我们正在讨论唯一ID,您可能需要2个部分,用户/站点唯一的“跨平台嵌入式javascript代码”以及支持它的任何服务器端代码。 Basically this is an API that is accessed using your own javascript widget. 基本上这是一个使用您自己的javascript小部件访问的API。 Feel free you point to examples in your requirements document, programmers love examples. 您可以在需求文档中指出示例,程序员喜欢这些示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM