• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1400
  • Last Modified:

pop-up window focus with PDF file

I am creating a pop-up window which displays a pdf file
selected from the main WEB page and, once loaded, attempting
to get the pdf pop-up window on top.

I am using Netscape 4.x and Javascript 1.2.

Everyting opens fine except the pop-up window disappers behind
the main window.

I am unable to include some dummy <form> statement in the
pdf window (the pdf file won't display).
Is there anyway I get the pdf pop-up window on top after the
pdf document is displayed?

Here's the simple javascript (big deal huh?):
function openPDFwindow(file2open) {
      PDFWin= window.open(file2open,'ViewPDF','toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=620,height=350')
}
0
blainerscsbl
Asked:
blainerscsbl
  • 4
  • 4
  • 2
  • +2
1 Solution
 
blainerscsblAuthor Commented:
Edited text of question.
0
 
knightEknightCommented:
You can try this:

function openPDFwindow(file2open) {
 PDFWin = window.open(file2open,'ViewPDF','toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=620,height=350');
PDFWin.focus();
}

.... but if you have HTML tags in file2open, then it is better to set the focus in there like this:

<BODY onLoad='self.focus();'>
0
 
blainerscsblAuthor Commented:
Doing a PDFWin.focus() doesn't work.  I even tried adding code to make sure the PDFWin window is 'created' before issuing the focus().  No luck.

Also, I am unable to insert <Body> or any other HTML tags in the PDFWin window.  Since this is displaying a pdf document  when I try to write a html tag into that window, the pdf document doesn't display (guess html and  pdf don't mix).
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
TTomCommented:
I'm being confused (or dumb).

I just tried three different methods of opening a PDF in a new window.  All of them left the new window on top (NS4.6).

<body onload="window.open('ReadMe.pdf','')">

or

<a href="javascript:window.open('ReadMe.pdf','')">Open PDF</a>

<body onload="OpenPDF()">

<script>
function OpenPDF() {
   PDFWin = window.open('ReadMe.pdf','')
}
</script>

What am I missing?

Tom

0
 
TTomCommented:
BTW,

The only time my PDF window did not bubble to the top was when it was already opened.

Tom
0
 
kmartin7Commented:
Try using a hidden frameset, 1 frame (hidden) with self.focus(), and the other with the PDF.

Open Window:

<html>
<script>
function openPDFwindow() {
  PDFWin = window.open('pdf-fset.htm', 'ViewPDF','toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=650,height=350');

             }
</script>
<body>
<a href="javascript:openPDFwindow()">Open PDF Window</a>
</body>
</html>

pdf-fset.htm:
<frameset rows="0,*" border=0>
     <frame src="hidden.htm" name="hidden">
     <frame src="myPDF.pdf" name="pdf">
</frameset>

hidden.htm:
<html>
<BODY onLoad='self.focus();'>
</body>
</html>

Kurt
0
 
Michel PlungjanIT ExpertCommented:
Kurt: This is better - no stripe in netscape:
<frameset rows="100%,*" border=0>
   <frame src="myPDF.pdf" name="pdf">
   <frame src="hidden.htm" name="hidden">
</frameset>

and why not do this:

function openPDFwindow(file2open) {
   PDFWin=window.open('blank.html','ViewPDF','toolbar=no,location=no,directories=no,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=620,height=350')

PDFWin.document.open();
PDFWin.document.write('<frame'+'set rows="100%,*" border=0 onLoad="if (window.focus) self.focus()">');
PDFWin.document.write('<frame src="'+file2open+'" name="pdf">');
PDFWin.document.write('<frame src="hidden.htm" name="hidden">');
PDFWin.document.write('</frame'+'set>');
PDFWin.document.close();
}

0
 
blainerscsblAuthor Commented:
Got It!!  Thanx for help from all of you.  Here's a synopsis (plus one question to mplugjan).
TTom:  You're not confused.  I'm using a cgi.  The timer delay value I used to give the window time to load the pdf file was not enough.  I had to wait about 5 seconds for the pdf file to load into the window before giving it focus.  Once I did this, my old code worked.  But, it was klugy.

I feel the kmartin7 and mplugjan solutions are more elegant and bring the window to focus immediately.  kmartin7's code helped me understand mplugjan's elegant solution.

One question:  if i do not have the 'hidden.htm' file on my server it still works.  My question: is it imperative the hidden.htm file exists and in fact loads into the frameset?

Now to allocate the points.  I'd like to give TTom 100 for his time and making me rething my existing code.
I'd like to give 200 each to kmartin7 and mplugjan.
If this is acceptable to all, can someone tell me how to allocate the points?? (I'll start looking on the web site to figure it out).
0
 
TTomCommented:
Glad to hear that all is functioning the way you want it to.

To allocate points, the easiest way would be to have me post an answer to this question (worth 100 pts) and post separate questions in the same area for Kurt and Michel with appropriate point values.

I suspect the answer to your question about "hidden.htm" is that it makes limited difference.  If the web server does not find "hidden.htm", it will send back a "404 - Not found" message.  The frameset will still load.

Thanks!!

Tom
0
 
blainerscsblAuthor Commented:
OK Tom!  Let's do what you suggest for allocating points.  Also, thanks for clarifiy the 'hidden.htm' question.
0
 
TTomCommented:
Always glad to help!

Hope that Michel will verify what I said about the hidden.html file, but I'm pretty sure I'm right.  You might want to put that to him in the question you post for him.

Tom
0
 
Michel PlungjanIT ExpertCommented:
I personally use
<FRAME SRC="javascript:' '">

to have an empty frame.
I suspect that leaving the line out all together should work since we do not care about the frame at all we only need the sideeffects of a frameset.

Michel
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now