jsPDF-No se permite navegar por el marco superior a la URL de datos


Después de actualizar Google Chrome, el informe jsPDF en una nueva ventana ya no funciona.

La consola muestra el mensaje:

No se permite navegar por el marco superior a la URL de datos: datos: aplicación / pdf; base64, JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1....

¿Puedes ayudarme?

Gracias.

Author: Difster, 2017-08-03

9 answers

Al parecer, Google Chrome ha eliminado el soporte para la navegación de marco superior, puede ver más información aquí: https://groups.google.com/a/chromium.org/forum/#! topic / blink-dev/GbVcuwg_QjM

Puede intentar renderizar el jsPDF a un iFrame

 24
Author: Pedro Calderon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-03 23:16:10

Esto funciona bien ahora que Chrome ha eliminado la navegación del marco superior. Solo descargar el pdf en Chrome da problema. Descargar funciona bien en firefox tho.

var string = doc.output('datauristring');
var iframe = "<iframe width='100%' height='100%' src='" + string + "'></iframe>"
var x = window.open();
x.document.open();
x.document.write(iframe);
x.document.close();
 27
Author: Joyston,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-21 05:02:43

Recientemente tuve el mismo problema al usar el objeto FileReader para leer contenido y mostrar mi JSReport.

 var reader = new FileReader();                        
 reader.onload = function (e) {
      window.open(reader.result, "_blank");
 }
 reader.readAsDataURL(blob);

Desafortunadamente después de la actualización de Chrome todo mi informe dejó de funcionar. Traté de arreglar esto mediante el uso de objeto Blob y todavía está funcionando, pero si tiene un bloqueador de ventanas emergentes no funcionará.

 var file = new Blob([blob], { type: 'application/pdf' });
 var fileURL = URL.createObjectURL(file);
 window.open(fileURL);

Finalmente encuentro una manera de evitar este problema creando el iFrame dinámicamente después de leer este tema y decidí compartir la solución .

 var file = new Blob([blob], { type: 'application/pdf' });
 var fileURL = URL.createObjectURL(file);
 var win = window.open();
 win.document.write('<iframe src="' + fileURL + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>')
 11
Author: Sadek Lallouani,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-15 20:14:03

Tal vez pueda ayudar, crear una función para exportar con el atributo de descarga html5:

var docPdf = doc.output();
exportToFile(docPdf,defaults.type);

function exportToFile(data,type){

    var hiddenElement = document.createElement('a');
    hiddenElement.href = 'data:text/'+type+';filename='+'exportar.'+type+';'+'charset=utf-8,' + encodeURI(data);
    hiddenElement.target = '_blank';
    hiddenElement.download = 'exportar.'+type;
    hiddenElement.click();
}
 4
Author: nikoz84,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-18 17:24:39
<iframe id="ManualFrame"
        frameborder="0"
        style="border:0"
        allowfullscreen>
</iframe>

<script>
    $(function () {
        setManualFrame();
    });

    function setManualFrame() {
        $("#ManualFrame").attr("height", screen.height);
        $("#ManualFrame").attr("width", screen.width);
        $("#ManualFrame").attr("src", "data:application/pdf;base64," + Your_PDF_Data);
    }
</script>
 1
Author: Lonely Planeteer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-16 06:04:35

Basado en Joyston ' s respuesta , pero sin reparsing y por lo tanto sin necesidad adicional de escapar de algo:

x=window.open();
iframe=x.document.createElement('iframe')
iframe.width='100%'
iframe.height='100%'
iframe.frameBorder=0
iframe.style="border: 0"
iframe.src='data:text/html........' //data-uri content here
x.document.body.appendChild(iframe);
 1
Author: T S,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-30 20:52:01
var pdfUrl = doc.output('datauri').substring(doc.output('datauri').indexOf(',')+1);
var binary = atob(pdfUrl.replace(/\s/g, ''));
var len = binary.length;
var buffer = new ArrayBuffer(len);
var view = new Uint8Array(buffer);
for (var i = 0; i < len; i++) {
    view[i] = binary.charCodeAt(i);
}

var blob = new Blob( [view], { type: "application/pdf" });
var url = URL.createObjectURL(blob);

function openPDF(){
    window.open(url);
}
 1
Author: Surya T,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-17 13:49:19

@kuldeep-choudhary

Hola, de hecho, para resolver estoy usando la etiqueta de objeto con AngularJS

<object ng-attr-data="{{data}}" type="application/pdf"></object>

Y en script:

$scope.doc.data = $sce.trustAsResourceUrl(doc.output("datauristring"));

En javascript puro, tal vez así funcione:

Html:

<object id="obj" type="application/pdf" ></object>

Js:

document.elementById('obj').data = doc.output("datauristring");

Por favor, trata de corregirme si me equivoco.

 1
Author: Márcio Rossato,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-22 10:20:54

No está relacionado con jspdf, pero me ayudó aquí (y esta pregunta es el éxito principal en Google): Si se especifica un atributo download="..." a la etiqueta de anclaje, el mensaje de descarga se abrirá correctamente.

 0
Author: Blauhirn,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-01 13:03:32