简体   繁体   English

包含没有 HTML 脚本标签的外部 JS 脚本

[英]Including external JS script without the HTML script tag

Pardon my ignorance, as my knowledge of JS is very shallow.请原谅我的无知,因为我对 JS 的了解非常浅薄。

I'm currently using UnrealJS to connect to a Google Javascript API.我目前正在使用UnrealJS连接到 Google Javascript API。 UnrealJS basically runs a V8 instance inside the Unreal 4 engine. UnrealJS 基本上在 Unreal 4 引擎中运行一个 V8 实例。 Considering that there's no conception of a DOM or HTML really inside UnrealJS, I need to be able to link to the external Google JS API script without the script tag:考虑到 UnrealJS 内部没有真正的 DOM 或 HTML 的概念,我需要能够链接到没有脚本标签的外部 Google JS API 脚本:

<script src="some-external-script-url" />

Is there a way to do this?有没有办法做到这一点? UnrealJS also supports Node.js - so if there's a way to do it with native Node.js, that would work as well. UnrealJS 也支持 Node.js - 所以如果有一种方法可以用原生 Node.js 做到这一点,那也可以。 I'v looked into using require() from Node, but it seems to only be available for local scripts.我研究过从 Node 使用 require(),但它似乎只适用于本地脚本。

Apologies if this question is too vague or hard to understand, I will edit it if need be.如果这个问题太模糊或难以理解,我会在需要时进行编辑。

I'm not familiar with UnrealJS, but you've mentioned you can run Node code, and require modules.我不熟悉 UnrealJS,但你提到你可以运行 Node 代码,并且require模块。 If that's the case, you can use an HTTP/S request to get the remote code, and then use vm.runInThisContext to inject the script into the current context.如果是这种情况,您可以使用 HTTP/S 请求获取远程代码,然后使用vm.runInThisContext将脚本注入当前上下文。 A sample code can be found in this answer .可以在此答案中找到示例代码。

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

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