+ Start a Discussion
Pasan   EeriyagamaPasan Eeriyagama 

Getting Lightning run-time exception: SecureWindow.open supports http://, https:// schemes and relative urls

Hi,

I'm trying to print preview a lightning component using below.
 
printPreview: function(component, event, helper) {
        var yourDOCTYPE = "<!DOCTYPE html>";
        var printPreview = window.open('about:blank', 'print_preview', "resizable=yes,scrollbars=yes,status=yes");
        var printDocument = printPreview.document;
        printDocument.open();
        printDocument.write(yourDOCTYPE+
                            "<html>"+
                            document.documentElement.innerHTML+
                            "</html>");
        printDocument.close();
        
    },

But it's throwing Lightning exception as below.

User-added image

Any suggestions/workaround to get this working please. Thanks.

 
NagendraNagendra (Salesforce Developers) 
Hi Pasan,

I guess it's due to the locker service 
Custom components run in “User mode” and don’t have access to the real Document or real “window” object.

That's why the above code will never work in Lightning Components.

Hope this helps.

Regards,
Nagendra