Click to See Complete Forum and Search --> : print image rather than page; close window w/o alert


eCat
10-06-2005, 01:21 PM
I've searched through about 200 relevant posts and haven't found what I was looking for, so I hope I'm not asking for something already solved!

I have a simple webpage which contains an image, a button to print the page and a button to close the window.

Here is my code to print & close (inside a form):

<input type=button name=print value="print this invitation" onClick="javascript:window.print()">

<input type=button value="close this window" onClick="javascript:window.close();">
My questions to the forum are:

1) can I use js to just print the image itself and not the whole page with the image and the two buttons on it?

2) is there a way to have js close the window without the "the web page you are viewing is trying to close..." alert box that pops up in IE?

Thanks!
eCat

MjhLkwd
10-06-2005, 03:27 PM
<HTML>
<Head>
<Style type='text/css' media='print'>

#above {display : none}
#below {display : none}

</Style>
</Head>
<Body>
<Span id='above'>
This is the page content above the image
</Span>
<br>
<img src='1.jpg'>
<br>
<Span id='below'>
This the page content below the image
</Span>
<br>
<br>
<input type='button' value='Print' onclick="window.print()">
</Body>
</HTML>

eCat
10-06-2005, 05:41 PM
Ah! Finally CSS code that makes sense to me. Thank you, Mike!

I don't suppose you also know the answer to the close window question? :D

MjhLkwd
10-06-2005, 06:13 PM
<HTML>
<Head>
<Script type="text/javascript">



window.opener = self;;

</Script>
</Head>
<Body>

<input type='button' value='Close' onclick="window.opener.close()">


</Body>
</HTML>

eCat
10-10-2005, 04:21 PM
You're my hero, Mike! :D

MjhLkwd
10-11-2005, 05:41 AM
You're welcome. Take care.