A project I'm working on requires the use of jQuery on customers' Web pages.(我正在从事的项目需要在客户的网页上使用jQuery。)
Customers will insert a chunk of code that we'll supply which includes a few <script>
elements that build a widget in a <script>
-created <iframe>
.(客户将插入我们将提供的代码块,其中包括一些<script>
元素,这些元素可在<script>
创建的<iframe>
中构建窗口小部件。) If they aren't already using the latest version of jQuery, this will also include (most likely) a <script>
for Google's hosted version of jQuery.(如果他们尚未使用最新版本的jQuery,则还可能(很可能)包含Google托管版本的jQuery的<script>
。)
The problem is that some customers may already have an older version of jQuery installed.(问题在于某些客户可能已经安装了旧版本的jQuery。) While this may work if it's at least a fairly recent version, our code does rely on some recently introduced functionality in the jQuery library, so there are bound to be instances when a customer's jQuery version is just too old.(尽管这可能至少有效,但是我们的代码确实依赖jQuery库中最近引入的某些功能,因此,在某些情况下,客户的jQuery版本太旧了。) We can't require that they upgrade to the latest version of jQuery.(我们不能要求它们升级到最新版本的jQuery。)
Is there any way to load a newer version of jQuery to use only within the context of our code, that will not interfere with, or affect, any code on the customer's page?(有没有办法加载新版本的jQuery以仅在我们代码的上下文中使用,而不会干扰或影响客户页面上的任何代码?) Ideally, maybe we could check for the presence of jQuery, detect the version, and if it's too old, then somehow load the most recent version just to use for our code.(理想情况下,也许我们可以检查jQuery的存在,检测版本,如果版本太旧,则以某种方式加载最新版本以用于我们的代码。)
I had the idea of loading jQuery in an <iframe>
in the customer's domain that also includes our <script>
, which seems like it might be feasible, but I'm hoping there's a more elegant way to do it (not to mention without the performance and complexity penalties of extra <iframe>
s).(我的想法是将jQuery加载到客户域的<iframe>
中,该域还包括我们的<script>
,这似乎是可行的,但我希望有一种更优雅的方法(更不用说额外的<iframe>
的性能和复杂性损失)。)
ask by Bungle translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…