我试图访问InDesign脚本中的远程.jsfile以使用它的变量。我找到了本地包含js-files的函数,但还没有找到包含的好方法。
http://remote-site.com/test.js:
var testVar = "it works!";
myscript.js,包括本地(工作):
app.doScript(new File("/Users/Popmouth/test.js"));
alert(testVar);
myscript.js,包括本地和远程(不工作):
app.doScript(new File("http://remote-site.com/test.js"));
alert(testVar);
我还发现了这个片段,这个警报工作(警报文件的内容,即"var testVar = "it works!;"
),但我不知道如何使用我的警报函数下面的变量:
var HTTPFile = function (url,port) {
if (arguments.length == 1) {
url = arguments[0];
port = 80;
};
this.url = url;
this.port = port;
this.httpPrefix = this.url.match(/http:\/\//);
this.domain = this.httpPrefix == null ? this.url.split("/")[0]+":"+this.port :this.url.split("/")[2]+":"+this.port;
this.call = "GET "+ (this.httpPrefix == null ? "http://"+this.url : this.url)+" HTTP/1.0\r\nHost:" +(this.httpPrefix == null ? this.url.split("/")[0] :this.url.split("/")[2])+"\r\nConnection: close\r\n\r\n";
this.reply = new String();
this.conn = new Socket();
this.conn.encoding = "binary";
HTTPFile.prototype.getFile = function(f) {
var typeMatch = this.url.match(/(\.)(\w{3,4}\b)/g);
if (this.conn.open(this.domain,"binary")) {
this.conn.write(this.call);
this.reply = this.conn.read(9999999999);
this.conn.close();
} else {
this.reply = "";
}
return this.reply.substr(this.reply.indexOf("\r\n\r\n")+4);;
};
}
var remoteFile = new HTTPFile("http://remote-site.com/test.js");
alert(.getFile());
此功能
1条答案
按热度按时间jvlzgdj91#
好的,我去了adobe-forums,得到了下面的字符串,它替换了
app.doScript(new File("/Users/Popmouth/test.js"));
: