코드? 그러나 기본적으로는 alert()
이 정의되어 있고 파일을 읽으려고 할 때 아무런 오류가 없다고 가정합니다. 그러나 alert()
은 코드에서 다른 곳에 정의하지 않는 한 정상적으로 정의되지 않습니다. 무엇 정확히 문제가 확정 될 수 있습니다. 에드 당신은 Browser Console에보고하는 경우 (Ctrl 키 - 시프트 - J, 또는 Cmd를 - 시프트 - OSX에 J을). 불행히도, 당신은 질문에 그 정보를 포함하지 않았습니다.
참고 정보 : 아래
는 완전한 파이어 폭스 애드온에 두 번 콘솔에 읽고 출력 SDK 확장에있는 파일.
read-text-file:readTextFile: This is a text file line 1
Line 2
read-text-file:readUtf8File: This is a text file line 1
Line 2
하는 index.js :
var {Cu} = require("chrome");
//Open the Browser Console (Used in testing/developmenti to monitor errors/console)
var utils = require('sdk/window/utils');
activeWin = utils.getMostRecentBrowserWindow();
activeWin.document.getElementById('menu_browserConsole').doCommand();
var buttons = require('sdk/ui/button/action');
var button = buttons.ActionButton({
id: "doAction",
label: "Do Action",
icon: "./myIcon.png",
onClick: doAction
});
//Above this line is specific to the Firefox Add-on SDK
//Below this line will also work for Overlay/XUL and bootstrap/restartless add-ons
//const Cu = Components.utils; //Uncomment this line for Overlay/XUL and bootstrap add-ons
const { TextDecoder, OS } = Cu.import("resource://gre/modules/osfile.jsm", {});
function doAction(){
var fileName = 'B:\\textFile.txt'
//Read the file and log the contents to the console.
readTextFile(fileName).then(console.log.bind(null,'readTextFile:'))
.catch(Cu.reportError);
//Do it again, using the somewhat shorter syntax for a utf-8 encoded file
readUtf8File(fileName).then(console.log.bind(null,'readUtf8File:'))
.catch(Cu.reportError);
}
function readTextFile(fileName){
var decoder = new TextDecoder();
return OS.File.read(fileName).then(array => decoder.decode(array));
}
function readUtf8File(fileName){
//Using the somewhat shorter syntax for a utf-8 encoded file
return OS.File.read(fileName, { encoding: "utf-8" }).then(text => text);
}
package.json :
{
"title": "Read a text file",
"name": "read-text-file",
"version": "0.0.1",
"description": "Reads a text file in two different ways.",
"main": "index.js",
"author": "Makyen",
"engines": {
"firefox": ">=38.0a1",
"fennec": ">=38.0a1"
},
"license": "MIT",
"keywords": [
"jetpack"
]
}
TEXTFILE 예시적인 텍스트 파일의 콘솔 출력은 아래에 포함. txt :
This is a text file line 1
Line 2
try/catch에서'OS.File.read()'를 래핑하고 OS.File.Error가 던져 졌는지 확인해 보셨습니까? https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/OSFile.jsm/OS.File.Error –
[종류의 Firefox 확장 기능] (https://developer.mozilla.org/en- (WebExtensions) (https://developer.mozilla.org/en-US/Add-ons/WebExtensions), [[태그 : fiirefox- addon-sdk]] [애드온 SDK] (https://developer.mozilla.org/en-US/Add-ons/SDK), [[태그 : firefox-addon-restartless]] [부트 스트랩 됨] (https : //developer.mozilla.org/en/US/Add-ons/Bootstrapped_extensions) 또는 [[tag : fiirefox-addon-overlay]] [오버레이/XUL/레거시] (https://developer.mozilla.org/en) -US/Add-ons/Overlay_Extensions))? 귀하의 질문에 해당하는 태그를 [편집]하십시오. – Makyen
[브라우저 콘솔] (https://developer.mozilla.org/en/US/docs/Tools/Browser_Console) (Ctrl-Shift-J 또는 OSX의 Cmd-Shift-J)에 * 정확하게 * 표시되었습니다. 이 코드를 실행할 때? – Makyen