Click to See Complete Forum and Search --> : Trying to print from a popup window


Dr. Possible
08-14-2003, 02:29 PM
I am trying to print a MS Word document.

I click "Print", a new window pops up, and it then loads the doc into the new window through Word's plug-in. Then it prints the doc but there is a prob.

When it prints, It prints a blank form with the pages and url on the bottom, not the document that is loaded on the page.

I think it is because of the line that says "msg.print()". But there is no such thing like "msg.document.print()".

This is the code I have"
----------------------------------------------------------------------
<script language="JavaScript">

var msg;
function WinOpen()
{
msg = open("test.doc","PopupWindow","toolbar=no,directories=no,menubar=no");
msg.document.open()
//msg.document.write("Example Text");
msg.print()
msg.document.close()
}

</script>
----------------------------------------------------------------------

Please help!
Thanks in advance,
Matthew.

Khalid Ali
08-14-2003, 03:06 PM
You don't have start new threads,you could have continued this with the older topic.:D

Now for the solution,
put this statement in the onload event in the popup window

self.focus()

Dr. Possible
08-15-2003, 08:44 AM
Thanks Khalid for the reply, and sorry about the multiple threads; I am used to vbCity's forums, where they tell you to only have one question per thread.

I still need a little help with this one, though. The popup window still never gets the focus, even though it is on top, because the printer always prints out a blank page.

I have included the code I use. All the commented parts are stuff that I have tried, but dont work.

This is my entire code in my .html notepad file:
----------------------------------------------------------------------
<html>

<script language="JavaScript">

function WinOpen()
{
var msg;
msg = open("test.doc","PopupWindow","toolbar=no,directories=no,menubar=no");
msg.document.open()
// msg.focus() <--- Doesn't do anything
// msg.document.focus() // <--- No error, but freezes computer
// msg.document.onload=self.focus() // <--- Doesn't do anything
// msg.document.onload=msg.document.focus() // <--- Doesn't do anything
// msg.document.onload=msg.focus() // <--- Doesn't do anything
msg.print()
msg.document.close()
}

function onload()
{
// self.focus() // <--- Doesn't do anything
}

</script>

<body>

<a href="#" onClick="WinOpen()">Print</a>

</body>

</html>
----------------------------------------------------------------------

Just wondering if you have any more ideas...

Also, how would I close the popup window after it has printed?

Thanks allot,
Matt.

Khalid Ali
08-15-2003, 08:50 AM
We have no roblem with the new topic in new thread as well,however if a question is related then it only makes sense to be in the one thread..anyways.

what is your code that opens the word document...?

I'll try to mimic the problem and see if it works for me

Dr. Possible
08-15-2003, 08:56 AM
Khalid,

Thanks for the fast reply.

There is no code for the document except for the line that says:
----------------------------------------------------------------------
msg = open("test.doc","PopupWindow","toolbar=no,directories=no,menubar=no");
----------------------------------------------------------------------

There is no code in the document or anything; just a line that says "Blahblahblah" so I can see if it printed or not. Also, there is no code in the popup window, which holds the document, because there is no real popup window; the JavaScript makes it durring run-time.

Do you want me to include the files?

Thanks,
Matt.

Khalid Ali
08-15-2003, 09:04 AM
nope...I thin I can write word doc for this purpose :-)

Let me see what I can do for you..

Dr. Possible
08-15-2003, 09:09 AM
Thanks for helping out :D
I'm kinda stuck on my own

P.S. test.doc is in the same folder as the .html file

Thanks,
Matt.

Khalid Ali
08-15-2003, 09:47 AM
This sis what I htink is happening.As soon as MS Wrod plugin opens the doc in the window,the actual window goes out of scope(seems like word doc creates a new display and paints ontop of the window that is opened)
there fore any code that you might have for previous poup is out of scope haning no effect on the current window that has ms doc in it.
Just an Idea,I think if the word document itself has some macro in it that prints it at load time that will work

Dr. Possible
08-15-2003, 09:53 AM
Thanks for trying Khalid,

I take it ther is no other way to print a document, besides going to it and pressing its print? ... or using macros.

Matt.

Dr. Possible
08-15-2003, 09:57 AM
Oh,

Do you think I could do it in vbScript? I'm not exactly sure what that is. Do most computers with the latest IE version have vbScript?

Thanks,
Matt.

Khalid Ali
08-15-2003, 11:38 AM
Originally posted by Dr. Possible
Thanks for trying Khalid,

I take it ther is no other way to print a document,

Matt.

well if you want to print an html page prgramattically that you can do for sure,however as I mentioned,the word document creates its own view area in the current window pushing the actual html document off scope,hence javascript has no control over that window and I am dead sure that using VBA you can control this behaviour and add some printing functionality by using a macro thta runs automatically as soon as word doc is loaded.

Dr. Possible
08-15-2003, 11:52 AM
OK, thanks allot for your help
Matt.

Khalid Ali
08-15-2003, 12:06 PM
you are welcome..:D