Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript Print and Focus not working

Posted on 2008-06-24
8
Medium Priority
?
522 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

722 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