我正在从脚本列表中创建一个Blob对象,然后从Blob创建对象URL以将脚本标记注入到html页面中。
var myScriptList = [
'var a = 1;',
'var b = 2;',
'var c = a+b;'
];
var myBlobObject = new Blob(myScriptList, {type: 'text/javascript'});
var urlToBlob = URL.createObjectURL(myBlobObject);
alert(urlToBlob);
当我需要使用相同的URL将新项目附加到我之前的blob时,会出现问题。我这样做是通过创建新的Blob对象来结合以前列表中的新项目:
var myScriptList = [
'var a = 1;',
'var b = 2;',
'var c = a+b;'
];
var myBlobObject = new Blob(myScriptList, {type: 'text/javascript'});
var urlToBlob = URL.createObjectURL(myBlobObject);
alert(urlToBlob);
myScriptList.push('console.log(c)');
myBlobObject = new Blob(myScriptList, {type: 'text/javascript'});
// Problem is following line returns new URL
urlToBlob = URL.createObjectURL(myBlobObject);
alert(urlToBlob);
但我需要为我的新对象保留以前的URL。可能吗?我怎么能这样做?