Solved

Javascript Print and Focus not working

Posted on 2008-06-24
8
484 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

743 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

13 Experts available now in Live!

Get 1:1 Help Now