function printMainWindowFrame() {
if (window.mainFrame) {
window.mainFrame.print();
} else if (window.frames['mainFrame']) {
window.frames['mainFrame'].focus();
window.frames['mainFrame'].print();
} else if (document.frames) {
document.frames('mainFrame').focus();
document.frames('mainFrame').print();
} else if (document.mainFrame) {
document.mainFrame.focus();
document.mainFrame.print();
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title</title>
<!-- This is specific to my application --->
<!-- I have another set of scripts that size the frameset in my application based on the browser and available screen size --->
<style type="text/css">
<!--
#mainFrame {
position:absolute;
left:150px;
top:75px;
width:800px;
height:800px;
z-index:2;
}
-->
</style>
<script language="javascript">
function mailpage() {
if (window.mainFrame) {
var MainFrameDOM = window.mainFrame.document.body;
var MainFrameTitle = window.mainFrame.document.title;
} else if (window.frames['mainFrame']) {
var MainFrameDOM = window.frames['mainFrame'].document.body;
var MainFrameTitle = window.frames['mainFrame'].document.title;
} else if (document.frames) {
var MainFrameDOM = document.frames('mainFrame').document.body;
var MainFrameTitle = document.frames('mainFrame').document.title;
} else if (document.mainFrame) {
var MainFrameDOM = document.mainFrame.document.body;
var MainFrameTitle = document.mainFrame.document.title;
}
document.getElementById('emailSubject').value=MainFrameTitle;
document.getElementById('emailPageFormBody').value=MainFrameDOM.innerHTML;
document.getElementById('emailPageForm').submit();
}
</script>
</head>
<body>
<!-- this frame is sized when the initial page loads and is sized to fill most of the browser window -->
<!-- this is the frame I want to set as my email function but it could be any frame in the DOM -->
<iframe id="mainFrame" frameborder="0"></iframe>
<!-- almost all application functions, form inputs, reports, etc... all load in the mainFrame everywhere in my application so at any point the user can use the image button for the email function and it will email the existing DOM in the mainFrame as they see it by grabbing the DOM - placing the entire DOM in the form and then pass that variable to the email function where it will simply email the page to their email address as its stored in the ColdFusion session variables -->
<!-- In my application this is in a div that shows only when the mouse is over a specific place in the menu system but you can use any text or image -->
<a href="javascript:mailpage();"><img src="/images/icons/mail2_16x16.gif" align="middle" border="0" style="cursor:hand;" ></a>
<!-- This form is at the very bottom of my page but it could exist anywhere in the document: -->
<!-- The most important part of this form is that its setup as a multiprt/form data and the method is post -->
<form enctype="multipart/form-data" name="emailPageForm" id="emailPageForm" method="post" style="display:none;" action="emailPageForm.cfm" target="processing">
<input type="hidden" name="FromAddress" value="<cfif IsDefined("session.user_settings.c_email")><cfoutput>#session.user_settings.c_email#</cfoutput></cfif>">
<input type="hidden" name="emailSubject" id="emailSubject" value="">
<input type="hidden" name="emailBody" id="emailPageFormBody" value="">
</form>
<!-- this frame is hidden so that the form processing goes to a frame that is not displayed to the user -->
<iframe id="processing" name="processing" style="display:none;" frameborder="0" width="0" height="0"></iframe>
</body>
<!-- this is the coldFusion page emailPageForm.cfm -->
<!-- this could also be done using php mail code -->
<cfmail to="#FromAddress#" subject="Page Requested From DSN" from="user@domain.com" server="mail.domain.com" type="html" username="username" password="password">
<cfoutput>#emailBody#</cfoutput>
</cfmail>
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)