Solved

Javascript Print and Focus not working

Posted on 2008-06-24
8
488 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
 

Author Comment

by:gjpitt
ID: 21865377
Full code of what?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

912 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now