我正在创建一个 object tag onload
,并在创建它之后尝试访问该对象,如下所示:
function loadFile() {
alert("loading file");
gform.MOJWebTwain.HTTPPort = 9080;
gform.MOJWebTwain.IfSSL = false;
var result = gform.MOJWebTwain.HTTPDownload('myServer', existingDocumentPath);
alert("result: "+result);
var errorString = gform.MOJWebTwain.ErrorString;
var errorCode = gform.MOJWebTwain.ErrorCode;
if (!result) {
alert("errorString: " + errorString);
alert("errorCode " + errorCode);
}
document.body.style.opacity="100";
}
window.onload = function () {
var DW_DWTContainerID = "gform:scan_area";
var DW_FULLCLASSID = "123456-abcdef-12345-abcdef-123456"; // fixed
var DW_PROCLASSID = "3d25aba1-abcdef-12345-abcdef-123456"; // the one in lpk file
var DW_VersionCode = "6,3,1,0";
var DW_InWindowsX86;
var objString = "";
var DW_ObjectName="MOJWebTwain"
var DW_Width = 400;
var DW_Height = 400;
var DW_CABX86Path = "DynamSoft/DynamicWebTWAIN.cab";
var DW_CABX64Path = "DynamSoft/DynamicWebTWAINx64.cab";
var LPK_Path = "DynamSoft/DynamicWebTwain.lpk";
ua = (navigator.userAgent.toLowerCase());
objString += "<object id='" + DW_ObjectName + "' "+"width='" + DW_Width +" ' "+"height='" + DW_Height+"' ";
if (DW_InWindowsX86) objString += "codebase='" + DW_CABX86Path + "#version=" + DW_VersionCode + "' ";
else objString += "codebase='" + DW_CABX64Path + "#version=" + DW_VersionCode + "' ";
objString += " classid='clsid:" + DW_FULLCLASSID + "' viewastext>";
//alert("objString: "+objString);
objString += " <param name='_cx' value='847'/>";
objString += " <param name='_cy' value='847'/>";
objString += " <param name='JpgQuality' value='30'/>";
objString += " <param name='Manufacturer' value='DynamSoft Corporation'/>";
objString += " <param name='ProductFamily' value='Dynamic Web TWAIN'/>";
objString += " <param name='ProductName' value='Dynamic Web TWAIN'/>";
objString += " <param name='VersionInfo' value='Dynamic Web TWAIN 6,3,1,0'/>";
objString += " <param name='TransferMode' value='0'/>";
objString += " <param name='BorderStyle' value='0'/>";
objString += " <param name='FTPUserName' value=''/>";
objString += " <param name='FTPPassword' value=''/>";
objString += " <param name='FTPPort' value='21'/>";
objString += " <param name='HTTPUserName' value=''/>";
objString += " <param name='HTTPPassword' value=''/>";
objString += " <param name='HTTPPort' value='9080' />";
objString += " <param name='ProxyServer' value=''/>";
objString += " <param name='IfDisableSourceAfterAcquire' value='0'/>";
objString += " <param name='IfShowUI' value='0'/>";
objString += " <param name='IfModalUI' value='-1'/>";
objString += " <param name='IfTiffMultiPage' value='-1'/>";
objString += " <param name='IfThrowException' value='0'/>";
objString += " <param name='MaxImagesInBuffer' value='99'/>";
objString += " <param name='TIFFCompressionType' value='0'/>";
objString += " <param name='IfFitWindow' value='-1' />";
objString += " <param name='IfSSL' value='0' />";
objString += " </object>";
var obj2String = "<object "
+"classid='clsid:"+DW_PROCLASSID+"'"+">"
+"<param name='LPKPath' value='"+LPK_Path+"'"+"/>";
+"</object>";
//alert("obj2String "+obj2String);
var obj2String = "<object classid='clsid:"+DW_PROCLASSID+"'>"
+"<param name='LPKPath' value='"+LPK_Path+"'"+"/>";
+"</object>";
var objects_string=obj2String +" "+objString;
DWTContainer = document.getElementById(DW_DWTContainerID);
DWTContainer.innerHTML = objects_string;
loadFile();
}
HTML如下:
<form id="gform">
<div id=gform:scan_area"">
</div>
</form>
但我总是知道我创建的对象null
在这一行:
gform.MOJWebTwain.HTTPPort = 9080;
如果对象是在页面中静态添加的(即不是通过onload
),我不会得到这个异常。