I am trying to call google translate inside window.open but it’s not working. When adding the Google translate script it showing blank page. I have shared with you the script code.
<script type="text/javascript">
function print() {
var tableHtml = `<table>
<tr>
<th>Items</th>
<th class='number-left'>Qty</th>
</tr>`;
items.forEach(function(item) {
tableHtml += `<tr>
<td>${item.name}</td>
<td class='number-left'>${item.qty}</td>
</tr>`;
});
tableHtml += `</table>`;
tableHtml += `<script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');}
</sc'+'ript>
<script src='https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit'></sc'+'ript>
`;
tableHtml += `<br><div id="google_translate_element"></div>`;
var divToPrint = document.getElementById('divToPrint');
var popupWin = window.open('', '_blank', 'width=400,height=400');
popupWin.document.open();
popupWin.document.write('<html><head>'+
'<style>' +
'.number-right{text-align: right;}' +
'</style>'+
'</head><body onload="window.print()">' + tableHtml +
'</html>');
popupWin.document.close();
}
</script>
I need to display Google Translate in popupWin.document.write. How I can achive that.