Solved

Javascript Print and Focus not working

Posted on 2008-06-24
8
512 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

634 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