4

I am trying to use ActiveXObject like below

getActiveXObject(pdfCtrl) {
      return new ActiveXObject(pdfCtrl);
    }

    checkPDF() {
        let plugin = null;
            if (this.getBrowser() === 'ie') {
                plugin = this.getActiveXObject('AcroPDF.PDF') || this.getActiveXObject('PDF.PdfCtrl');
        }
        return plugin;
    }

It gives error like ActiveXObject not found. In plain JS this works, but in Angular/typesript compilation phase it throws error. How do i handle this?

Hacker
  • 7,798
  • 19
  • 84
  • 154
  • *'it throws error'* - this tells us nothing! Please specify what error it is that you're getting. – Joe Clay Jan 24 '18 at 14:47
  • 1
    Also, I'd very, very heavily recommend avoiding ActiveX unless you have no other choice. It's not supported in any modern browsers, and there's native JS libraries like PDF.js which will do the same job. – Joe Clay Jan 24 '18 at 14:49
  • ActiveXObject not found is the error thrown. – Hacker Jan 24 '18 at 14:53
  • Any news on this question? I'm facing the same issue – D. Pesc. Oct 31 '18 at 11:55

1 Answers1

0

example for msxml - ActiveXObject is available only in IE, in Chrome using native methods:

 import * as ts from "typescript";
 ...
  private loadMsXml(src: string): any {
    let code: string = `({
      Run: (data: string): any => {
        let doc = new ActiveXObject("Msxml2.DOMDocument.6.0");
        doc.async = false;
        doc.loadXML(data);
        return doc;
      })`;
    const e = eval;
    let result = ts.transpile(code);
    let runnalbe: any = e(result);
    return runnalbe.Run(src);
  }

  private transformXml(xmlDoc: any, xsltDoc: any): string {
    if (this.isBrowserIE()) {
      let xmlDocMS = this.loadMsXml(new XMLSerializer().serializeToString(xmlDoc));
      let xslDocMS = this.loadMsXml(new XMLSerializer().serializeToString(xsltDoc));
      let resultXml = xmlDocMS.transformNode(xslDocMS);
      return resultXml;
    }

    let xsltProcessor = new XSLTProcessor();
    xsltProcessor.importStylesheet(xsltDoc);
    let resultDoc = xsltProcessor.transformToDocument(xmlDoc);
    let resultXml = new XMLSerializer().serializeToString(resultDoc);
    return resultXml;
  }
Sasha Bond
  • 984
  • 10
  • 13