「スクリプトの読み込み」の編集履歴(バックアップ)一覧はこちら

スクリプトの読み込み」(2014/11/16 (日) 16:00:39) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

-[[Appendix D: Loading Scripts - Mozilla | MDN>https://developer.mozilla.org/en-US/Add-ons/Overlay_Extensions/XUL_School/Appendix_D:_Loading_Scripts]] #contents() *XUL の script タグで読み込む #highlight(xml){ <script type="application/javascript" src="sample.js"/>} *Sub-Script Loader で読み込む #highlight(javascript){{ Cu.import("resource://gre/modules/Services.jsm"); var tmp = {}; Services.scriptloader.loadSubScript("chrome://sample/content/sample.js", tmp, "UTF-8"); var sample_function = tmp.sample_function; var sample_array = tmp.sample_array; }} loadSubScript の第2、第3引数は省略可能。 *サンドボックスを使用して読み込む -[[Components.utils.Sandbox | MDN>https://developer.mozilla.org/en-US/docs/Components.utils.Sandbox]] -[[Components.utils.evalInSandbox | MDN>https://developer.mozilla.org/en-US/docs/Components.utils.evalInSandbox]] 例としてローカルファイルをサンドボックスで読み込んでみる。 #highlight(javascript){{ Cu.import("resource://gre/modules/osfile.jsm"); const filePath = "C:\\temp\\sample.js"; let promise = OS.File.read(filePath, { encoding: "utf-8" }); promise.then(text => { var sandbox = new Cu.Sandbox(this, {wantComponents:false}); try { Cu.evalInSandbox(text, sandbox); } catch (e) {} var sample_function = sandbox.sample_function; var sample_array = sandbox.sample_array; }); }}
-[[Appendix D: Loading Scripts - Mozilla | MDN>https://developer.mozilla.org/en-US/Add-ons/Overlay_Extensions/XUL_School/Appendix_D:_Loading_Scripts]] #contents() *XUL の script タグで読み込む #highlight(xml){ <script type="application/javascript" src="sample.js"/>} *Sub-Script Loader で読み込む -[[mozIJSSubScriptLoader - Mozilla | MDN>https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/mozIJSSubScriptLoader]] #highlight(javascript){{ Cu.import("resource://gre/modules/Services.jsm"); var tmp = {}; Services.scriptloader.loadSubScript("chrome://sample/content/sample.js", tmp, "UTF-8"); var sample_function = tmp.sample_function; var sample_array = tmp.sample_array; }} loadSubScript の第2、第3引数は省略可能。 *サンドボックスを使用して読み込む -[[Components.utils.Sandbox | MDN>https://developer.mozilla.org/en-US/docs/Components.utils.Sandbox]] -[[Components.utils.evalInSandbox | MDN>https://developer.mozilla.org/en-US/docs/Components.utils.evalInSandbox]] 例としてローカルファイルをサンドボックスで読み込んでみる。 #highlight(javascript){{ Cu.import("resource://gre/modules/osfile.jsm"); const filePath = "C:\\temp\\sample.js"; let promise = OS.File.read(filePath, { encoding: "utf-8" }); promise.then(text => { var sandbox = new Cu.Sandbox(this, {wantComponents:false}); try { Cu.evalInSandbox(text, sandbox); } catch (e) {} var sample_function = sandbox.sample_function; var sample_array = sandbox.sample_array; }); }}

表示オプション

横に並べて表示:
変化行の前後のみ表示: