Onload event is not firing after passing Html string through in Angular 8


I have a scenario, I am receiving Html comtent as a string from java service and I am trying to render this through Angular using method. Html elements are data is diplaying, but while loading window javascript onload event is not triggering.

Html string receiving from java:

<html><h1>Workflow Detailed Report modified</h1><head><script type=text/javascript>function loadReport() {alert('Load Report');"","_self")}</script></head><body onload="loadReport()"></body></html>

In Angular function using below code to open new window with above string.

const win ='', '_blank', 'left=50,top=50,width=1334,height=700');

Is there any better way to handle this scenario in Angular 8.


When using document.write(), you have to call document.close() afterwards to finalize the document, otherwise the load event will not be fired.

const win ='', '_blank', 'left=50,top=50,width=1334,height=700');

Answered By – aweebit

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published