Printing a new window

Mar 05, 2019

Hi everyone,

I'm currently making a course that helps participants to build a specific document. There are multiple sections where they can write their own notes/things to add in it.

What I'm trying to do, is to then take all the text they entered, put it in a new html window, and let them print it. I collect all the informations in variables, and use a Javascript trigger to create the window.

I've been trying to test this with this code without success: 

var newWindow = window.open("","Print","width=816,height=900,scrollbars=1,resizable=1");

var player=GetPlayer();
var text1 = player.GetVar("t1");
var text2 = player.GetVar("t2");
var text3 = player.GetVar("t3");

contents ="<h1>Test</h1>";
contents += "<p>1: "+text1+"</p>";
contents += "<p>2: "+text2+"</p>";
contents += "<p>3: "+text3+"</p>";
contents +="<button onclick='window.print()'>Print</button>"
newWindow.document.write(contents);

 

The new window appears, but the print button does not work. A small window at the bottom tells me that IE blocked the executions of some scripts, and when I click to autorize it, the page is replaced with a copy of the storyline slide. I tried to do this in a regular html document to check if my code had any problems, but it seems to be working fine. My guess is that it works with chrome, but not with IE. Is there a way to make sure it works with all browser? Especially since most people tend to have IE by default, and that this javascript code always open an IE window.

1 Reply
OWEN HOLT

I'm not sure if this will solve the problem or not, but you aren't declaring the contents variable before building it out.

var newWindow = window.open("","Print","width=816,height=900,scrollbars=1,resizable=1");

var player=GetPlayer();
var text1 = player.GetVar("t1");
var text2 = player.GetVar("t2");
var text3 = player.GetVar("t3");

var contents ="<h1>Test</h1>";
contents += "<p>1: "+text1+"</p>";
contents += "<p>2: "+text2+"</p>";
contents += "<p>3: "+text3+"</p>";
contents +="<button onclick='window.print()'>Print</button>"
newWindow.document.write(contents);




This discussion is closed. You can start a new discussion or contact Articulate Support.