Solved

Javascript Print and Focus not working

Posted on 2008-06-24
8
498 Views
Last Modified: 2009-10-13
Hi Guys

The code attached is my replacement for a frameset page but I do need to print the contents of iFrameMain now and again.

I have a main that sits the iFrameMenu and I'm looking for the correct javascript commands that will allow me to print whatever is in iFrameMain.

I've tried many variations on a theme based on the idea that you should set the focus to theframe first then print....

document.frames.iFrameMain.focus();
document.frames.iFrameMain.print();


<%@ Language=VBScript %>
<%option explicit%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<meta name=vs_snapToGrid content="False">
		<meta name=vs_showGrid content="False">
<title>FrameSet</title>
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
		<meta name="ProgId" content="VisualStudio.HTML">
		<meta name="Originator" content="Microsoft Visual Studio .NET 7.1">
</head>
	<body ms_positioning="gridlayout" style="BACKGROUND-IMAGE: url(images/WebFront.jpg); BACKGROUND-REPEAT: repeat-x">
		<table id="table1" style="Z-INDEX:100; LEFT:0px; POSITION:absolute; TOP:0px" top:0px left:0px width="178px" height="100%" border="0">
			<tr>
				<td style="HEIGHT: 300px;BACKGROUND-COLOR: transparent" >
				<iframe scrolling=no name="iFrameMenu" id="iFrameMenu" src="<%=Session("MenuSelector")%>" width="100%" height="100%" allowTransparency="true" frameborder=no></iframe>
				Menu
				</td>
			</tr>
			<tr>
				<td style="BACKGROUND-COLOR: transparent">
				<iframe scrolling=no name="iFrameStats" id="iFrameStats" src="stats.asp" width="100%" height="100%" allowTransparency="true" frameborder=no></iframe>
 
				</td>
			</tr>
		</table>
		<table id="table2"  style="Z-INDEX:101; LEFT:179px; WIDTH:1000px; POSITION:absolute; TOP:0px; HEIGHT:800px" top:0px left:178px width="1000" height="800" border="0">
			<tr height="11%">
				<td style="HEIGHT: "185px"; BACKGROUND-COLOR: transparent">
				<iframe scrolling=no name="iFrameHeader" id="iFrameHeader" src="awelcome.aspx" width="100%" height="100%" allowTransparency="true" frameborder=no></iframe>
				</td>
			</tr>
			<tr height="89%">
				<td style="BACKGROUND-COLOR: transparent">
				<iframe scrolling=no name="iFrameMain" id="iFrameMain" src="MView.aspx" width="100%" height="100%" allowTransparency="true" frameborder=no></iframe>
				</td>
			</tr>
		</table>
	</body>
</html>

Open in new window

0
Comment
Question by:gjpitt
  • 4
  • 4
8 Comments
 
LVL 22

Expert Comment

by:neeraj523
ID: 21858465
Hello

Following statement can set focus at main frame.. but i dont think there is any way to print only content in iframe..

<body ms_positioning="gridlayout" style="BACKGROUND-IMAGE: url(images/WebFront.jpg); BACKGROUND-REPEAT: repeat-x" onLoad="document.getElementById('iFrameMain').focus()">
0
 

Author Comment

by:gjpitt
ID: 21859316
Object donesn't support this property or method is the response I get.

Bear in mind that I can only use a script attached to a button, i.e. click button action takes place.

0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21862789
can you post your full code ?
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:gjpitt
ID: 21865377
Full code of what?
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21866956
"Full code of what ??"

Are you really not sure or just kidding ?? Are we not talking about the issue in your code  ??



0
 

Author Comment

by:gjpitt
ID: 21867689
I really wasn't sure. My full code for the frames page is shown above so I assumed you had seen that. The Full code for the menu I don't know where it is because it is part of AllWebMenus. The Full code for the site would be too large to post here - about 1200 pages!!

As it is I have now found a solution which is shown below.

Thanks anyway
in the Head section
 
<script type="text/javascript">
function PrintIframe()
{
window.parent.iFrameMain.focus();
window.print();
}
</script>
 
and to make it work
 
PrintIframe(); on the button click event

Open in new window

0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21872060
so you got your issue resolved ??
0
 

Accepted Solution

by:
gjpitt earned 0 total points
ID: 21876425
Yes but many thanks for your help
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
why $(this).attr('id'); function not returning value ? 9 53
Not allowed to load local recource. 4 35
Access RV042 GUI / Browser Issues 25 49
jQuery Dialog Autoresize Bug 2 25
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question