In order to facilitate migration from ScriptX.Add-on to ScriptX.Services, MeadCo has created an emulation library ScriptX.Print.Client. This enables existing code that targets ScriptX.Add-on (and so can only run in Internet Explorer) to carry on working on a page that targets ScriptX.Services.
The library is designed in such a way that ScriptX.Add-on will be used if the client is internet Explorer and the traditional ScriptX <object>
tags are included on the page. As a result, web pages that previously would only work and print from Internet Explorer can now function in any modern web browser, and if you are using ScriptX.Services for Cloud or ScriptX.Services for On-Premise Devices the browser could be running on any device.
Below is an extract from A sample from then to now which is a worked-through example of upgrading an existing ScriptX.Add-on page to work with the add-on in Internet Explorer or ScriptX.Services in any other browser. In order to highlight the principle this code has been kept as simple as possible. In a production environment there would normally be error handling, confirmation of a valid license etc etc.
Here is the relevant code from a simple ScriptX-enabled page that was written for ScriptX.Add-on and assumes that ScriptX is already installed on the client machine (no “codebase” parameter):
<html>
<head>...</head>
<body onload="initView()">
<!-- MeadCo Security Manager -->
<object id="secmgr" viewastext style="display:none"
classid="clsid:5445be81-b796-11d2-b931-002018654e2e">
<!-- substitute your license for {C4DB5D29....} -->
<param name="GUID" value="{C4DB5D29-BE52-46B9-9DDF-46A167170F81}" />
<param name="PATH"
value="https://licenses.meadroid.com/download/{C4DB5D29-BE52-46B9-9DDF-46A167170F81}/mlf" />
<param name="REVISION" value="10" />
<param name="PerUser" value="true">
</object>
<!-- MeadCo ScriptX -->
<object viewastext id="factory" style="display:none"
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814">
</object>
<script>
function initView() {
<!-- apply custom settings -->
factory.printing.enhancedFormatting.allPagesHeader =
"<div><center><img src='//services.meadroid.com/images/sx-header.png'>" +
"</center></div>";
factory.printing.enhancedFormatting.allPagesFooter =
"<div><center>" +
"<img src='//services.meadroid.com/images/sx-footer-final.png'>" +
"</center></div>";
<!-- set inches -->
factory.printing.SetMarginMeasure(2);
factory.printing.header = "";
factory.printing.footer = "";
factory.printing.leftMargin = 1.0;
factory.printing.topMargin = 1.5;
factory.printing.rightMargin = 1.0;
factory.printing.bottomMargin = 1.5;
}
function printContent() {
factory.printing.Print();
}
</script>
<div>Some content to print</div>
<div><button id="btn-print" onclick="printContent();">Print</button></div>
</body>
</html>
If you are viewing this in Internet Explorer and already have ScriptX installed on your machine you can see this code in action here.
In order to upgrade the page to make it compatible with ScriptX.Services when viewed in a browser other than Internet Explorer, all that is needed is to add a reference to the ScriptX.Print.Client library and to jQuery (as the library currently has a dependency on jQuery – it is planned that a future version will remove this dependency).
<!-- scriptx.services requires jquery -->n <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>nn <!-- Add.on to scriptx.services compatibility -->n <script
src="//cdn.jsdelivr.net/npm/scriptxprint-html/dist/meadco-scriptxservices.min.js"n data-meadco-license="{C4DB5D29-BE52-46B9-9DDF-46A167170F81}"n data-meadco-server="http://127.0.0.1:41191"n data-meadco-license-path="warehouse"n data-meadco-license-revision="10"n data-meadco-syncinit="true"></script>n
This code assumes that ScriptX.Services for Windows PC is installed on the client’s machine. All existing, valid ScriptX.Add-on licenses have been upgraded (free of charge) to enable use of ScriptX.Services for Windows PC, so the license GUID value remains unchanged.
You can see this code in action here, and a longer, more detailed version of this article can be read here.
Note that if your code makes use of asynchronous functionality in the MeadCo wrapper and compatibility libraries you will require a reference to a ‘promise’ polyfill in order for it to function in Internet Explorer. We recommend (and test with) Taylor Hakes’ Promise Polyfill.