rldjrsksl / flex-iframe

Automatically exported from code.google.com/p/flex-iframe
0 stars 0 forks source link

printIFrame doesn´t work when using iframe "content" #74

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create IFrame
2. Use "content" to set your HTML
3. Call printIFrame function of iframe

What is the expected output? What do you see instead?
Expected print dialog.
I see nothing.

What version of Flex-IFrame are you using? On what operating system and
which navigator (specify the version too)?
flex-iframe = 1.4.3
Windows XP
Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-BR; rv:1.9.2) Gecko/20100115
Firefox/3.6 (.NET CLR 3.5.30729)
IE 8.0.6001

Please provide any additional information below, and a sample Flex 3
project reproducing the issue if possible.
The problem occurs when you use "content", the flex-iframe creates a DIV
and when you call print function javascript throws an exception saying
"document[...] is null or ..."

Original issue reported on code.google.com by ricardo....@gmail.com on 19 Mar 2010 at 4:36

Attachments:

GoogleCodeExporter commented 8 years ago
Print it's not possible for "content" because there is no <iframe /> tag in 
HTML... 

Original comment by szczepanski.jaroslaw on 12 May 2010 at 12:25

GoogleCodeExporter commented 8 years ago
You're right !

Original comment by Julien.N...@gmail.com on 14 May 2010 at 3:32

GoogleCodeExporter commented 8 years ago

Original comment by Julien.N...@gmail.com on 14 May 2010 at 5:03

GoogleCodeExporter commented 8 years ago
There actually is a way to print the content of a div. An example can be found 
at:

http://stackoverflow.com/questions/468881/print-div-idprintarea-div-only

I tested this in the latest versions of Internet Explorer, Firefox, Opera, and 
Google Chrome and it worked consistently in all browsers.

Here is the code:
------------------------------------------------------------------------------

****************************Do not print this.

<br />

<script language="javascript">

var gAutoPrint = true;

function processPrint(oDivObject){

if (document.getElementById != null){

var html = '<HTML>\n<HEAD>\n';

if (document.getElementsByTagName != null){

var headTags = document.getElementsByTagName("head");

if (headTags.length > 0) html += headTags[0].innerHTML;

}

html += '\n</HE' + 'AD>\n<BODY>\n';

var printReadyElem = document.getElementById(oDivObject);

if (printReadyElem != null) html += printReadyElem.innerHTML;

else{

alert("Error, no contents.");

return;

}

html += '\n</BO' + 'DY>\n</HT' + 'ML>';

var printWin = window.open("","processPrint");

printWin.document.open();

printWin.document.write(html);

printWin.document.close();

if (gAutoPrint) printWin.print();

} else alert("Browser not supported.");

}

</script>

<div id="oDivContent">
This is the content to print.
</div>

<br />

<a href="javascript:void(processPrint('oDivContent'));">Print</a>

<br />

****************************Do not print this.

------------------------------------------------------------------------------

Original comment by charles....@gmail.com on 16 Sep 2010 at 11:53

Attachments:

GoogleCodeExporter commented 8 years ago
I would also think that rather than displaying content in a div you could 
probably display it in the iframe by setting the content of the iframe using 
the innerHTML property.

See below:

var myIFrame = document.getElementById(iFrameName);
var content = myIFrame.contentWindow.document.body.innerHTML;

Original comment by charles....@gmail.com on 17 Sep 2010 at 12:00