views:

54

answers:

2

So I have a quiz users take, and at the end they obviously get results.

There is a "Print Results" feature which the client wants to load into a new window with new css etc...

My question is, how do I pass the results to a new window using javascript? Normally I would do this all with session, but the quiz and results were all done with javascript.

I basically have this:

$('#quizId .printQuiz').live("click", function(event) {
        event.preventDefault();
        resultsHtml = $('#quizResultsContent').html();

        window.open('QuizResults.htm', "Print", "status=0,toolbar=0");
}

I need to pass resultsHtml to the QuizResults.htm page. Is this even possible?

+2  A: 

In the target page you can use window.opener to refer back to the original window and pull out whatever data or markup you want.

It might be better though to create a print-friendly CSS so a user can print the original page without having to open a new page (although this has the downside that a user may expect it not to print well even though it will).

Sam
+2  A: 

You can also write to the window directly, you don't need an actual page:

<script type="text/javascript">
    var w = window.open(null, '_blank');
    w.document.open();
    w.document.write('hello world');
    w.document.close();
</script>
Chris Haas
exactly what I was looking for. Thanks Chris!
Jack Marchetti