|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Firstly I'll own up to not being a code monkey, so I really do need some help.
I require a javascript code to focus and print an iFrame called 'stocklist_content' I need to be able to do this by placing a link in the parent frame and a seperate within the iFrame itself. I have found a few articles on the subject but no complete examples of the required code. Can anyone provide a full example? Thanks in advance, elemental |
|
#2
|
||||
|
||||
|
focus() the iframe than print() it (by the way, print() method works on IE only).
|
|
#3
|
||||
|
||||
|
Try something like this:
Code:
<script type="text/javascript">
<!--
function PrintF(){
var IFRAME = document.getElementById("MyIframe");
IFRAME.print();
}
//-->
</script>
Code:
<form action="" method="post"> <input type="button" value="Print!" OnClick="PrintF();" /> </frame>
__________________
RyanJ (Ryan Jones) General Links: ( Jick's Blog | W3C Validation | W3C CSS Validation ) Manuals: ( PHP Manual | MySQL Manual ) Ways to help with tsunami relief |
|
#4
|
|||
|
|||
|
I'm very impressed with the prompt replies, thanks.
sciguyryan I have used your code e.g. http://www.sentinalcars.com/stocklist.html but get the following error in Explorer 6: IFRAME.print(); Quote:
Quote:
|
|
#5
|
|||
|
|||
|
#6
|
||||
|
||||
|
Ok, sorry about that it seems I used an incorrect idea
![]() try this: Code:
<script type="text/javascript">
<!--
function PrintF(){
document.FrameName.focus();
document.FrameName.print();
}
//-->
</script>
__________________
RyanJ (Ryan Jones) General Links: ( Jick's Blog | W3C Validation | W3C CSS Validation ) Manuals: ( PHP Manual | MySQL Manual ) Ways to help with tsunami relief |
|
#7
|
|||
|
|||
|
No change
Quote:
[quote]document.stocklist_content.print();[\QUOTE] Next...
|
|
#8
|
||||
|
||||
|
Thats odd, when I looked this up that was the syntax used on another site :S
If I get any other ideas I'll post them for you to try.
__________________
RyanJ (Ryan Jones) General Links: ( Jick's Blog | W3C Validation | W3C CSS Validation ) Manuals: ( PHP Manual | MySQL Manual ) Ways to help with tsunami relief |
|
#9
|
||||
|
||||
|
#10
|
|||
|
|||
|
We're back on track, thanks fredmv.
Now the iframe content prints but not fully... it cuts off at the bottom of the printed page border... Any ideas? |
|
#11
|
|||
|
|||
|
The responses have stopped flowing... ok let me rephraise the question before I abandon iframes forever. How do I force the browser to print the entire contents of the iframe?
thanks in advance, elemental. |
|
#12
|
||||
|
||||
|
Abandoning iframes is the best idea of the thread so far (most probably you were using them for all the wrong reasons anyway). :thumbsup:
__________________
Vladdy Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it. |
|
#13
|
|||
|
|||
|
my way
Tested in IE7
Code:
<head>
<script type="text/javascript">
function ClickHereToPrint(){
try{
var oIframe = document.getElementById('ifrmPrint');
var oContent = document.getElementById('divToPrint').innerHTML;
var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
if (oDoc.document) oDoc = oDoc.document;
oDoc.write("<html><head><title>title</title>");
oDoc.write("</head><body onload='this.focus(); this.print();'>");
oDoc.write(oContent + "</body></html>");
oDoc.close();
}
catch(e){
self.print();
}
}
</script>
</head>
<body>
<a onclick="ClickHereToPrint();">Print</a>
<iframe id='ifrmPrint' src='#' style="width:0px; height:0px;"></iframe>
<div id="divToPrint">
content
</div>
</body>
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|