Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open New window with specified contents

Status
Not open for further replies.

bam720

Technical User
Sep 29, 2005
289
US
I am on a page where I have some nifty graphs (made in css/html). I'd like to pass the contents of these graphs to another pop up page in case the user would like to print. I've grabbed the entire containing div element on my page and want to pass it the page below. The content is being passed in fine, but I can't figure out how to change the content of the page. I keep getting $('print_content') is null. Any help would be great.

Code:
function print_window(css_id)
{
  var content = $(css_id); if(!content) return;
  var win = window.open('/ajax/print.php', 'print');

  $('print_content').replace(content.innerHTML);
  console.log(content.innerHTML);
  console.log(win.document);
}

=========================================================

<html>
<head>
<title> </title>
<link rel="stylesheet" type="text/css" href="/css/style.css" />
<script type="text/javascript" src="/js/prototype/prototype.js"></script>
<script type="text/javascript">
</script>
</head>
<body>
<div style="margin:30px;">
<div class="h2" style="width:574px;"><?php echo $title; ?></div>
<div id="print_content">

</div>
</div>
</body>
<html>
 
If the 'print_content' code is running in your opener, then that's your problem. You need to do the lookup in the context of the new window, 'win'.

Try something like:

Code:
win.$('print_content').replace(content.innerHTML);

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I get this in the console:
win.$ is not a function
[Break on this error] win.$('print_content').replace(content.innerHTML);
 
I worked around it by using
Code:
var html = "html here"+ content.innerhtml+ "more html";
var doc = win.document'
doc.open("text/html", "replace");
doc.write(html);
doc.close();

not as pretty but gets the job done
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top