Browser: IE
Question: Browser only one scriptx object can be used per browser window error
The introduction of general ScriptX controls needs to be written in the current file as follows:
<object id="factory" style="display: none" viewastext="" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="../../smsx.cab#Version=6,5,439,30">
</object>
But when you open two documents to be printed continuously in one window, only one print file can print normally, and the other cannot print and preview. The reason for reporting an error of only one scriptx object can be used per browser window is that each browser window has only one ScriptX object, and you open more than two prints under that browser window. Document, every print file has a print object, so it will report errors. To solve this problem, we must first consider that we must not let every print file introduce a ScriptX object. So I did not write the above code to the current file, but introduced an external js file, which contains creating a ScriptX object and printing format content, such as print buttons. The corresponding method is written as follows (Principle: Introduce the ScriptX object before printing and remove it after printing)
//preview
function Preview() {
//
if(!document.getElementById("inScriptX")){
var scriptX=document.createElement("div");
scriptX.id="inScriptX";
document.body.appendChild(scriptX);
}
document.getElementById("inScriptX").innerHTML="<object id='factory' style='display:none' viewastext classid='clsid:1663ed61-23eb-11d2-b92f-008048fdd814' codebase='../../smsx.cab#Version=6,5,439,30'></object>";
if (!factory.object) {
alert("Print control not installed correctly!");
return false;
}
set_print();
document.getElementById("factory").printing.Preview();
document.getElementById("inScriptX").innerHTML="";
}
//Printing
function Print() {
try{
if(!document.getElementById("inScriptX")){
var scriptX=document.createElement("div");
scriptX.id="inScriptX";
document.body.appendChild(scriptX);
}
//Create a ScriptX Print Object before Printing
document.getElementById("inScriptX").innerHTML="<object id='factory' style='display:none' viewastext classid='clsid:1663ed61-23eb-11d2-b92f-008048fdd814' codebase='../../smsx.cab#Version=6,5,439,30'></object>";
if (!factory.object) {
alert("Print control not installed correctly!");
return false;
}
set_print();
factory.printing.Print(false);
//Clear immediately after printing
document.getElementById("inScriptX").innerHTML="";
}catch(e){
alert(e.message)
}
}
//Setting Print Style
function set_print(){
factory.printing.header = ""
factory.printing.footer ="";
factory.printing.leftMargin = 6;//left
factory.printing.topMargin = 0;//top margin
factory.printing.rightMargin =6;//Right margin
factory.printing.bottomMargin = 10;//margin-bottom
}