Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript-Firefox problem: browser gets the wrong message 1

Status
Not open for further replies.

crtyro

Programmer
Jun 10, 2007
5
US
Attempting to open a PDF file from link in a distant folder.
Three files and their locations:
(letters spaced to get by forum editor)
(* instead of period)
Code:
d:\k\t\W E B P D F*J S            j a v a s c r i p t
d:\k\t\S A M P L E*P D F          P D F file
d:\k\t\down1\down2\T E S T*H T M  calling file

JS content:
  <SCRIPT LANGUAGE="JavaScript" SRC="..\..\WEBPDF.JS"></SCRIPT>
  <a href="javascript:PDFOpen('\k\t\SAMPLE.PDF',t)">use link</a>

test.htm content:
<!-- Hide the following from other browsers
function PDFOpen(PDFURL,PDFName)
  {
   var HTMLname = PDFURL.substring(0,6)
   var PDFOption='toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no,fullscreen=yes'
   PDFWin=document.open(PDFURL,HTMLname,"'"+PDFOption+"'")
   PDFWin.moveTo(0,0);
   PDFWin.resizeTo(screen.width,screen.height);
  }
// Stop hiding JavaScript -->

I have no previous experience with JavaScript, copied this from a friend.
The link seems to work ok, but browser gets the wrong address,
"Firefox can't find the file at d:/k/t/down1/down2/SAMPLE.PDF"
But the file is at d:\k\t\SAMPLE.PDF
Explorer too says "This file cannot be displayed" but does not give the address.

Is it possible to open a PDF file in a distant folder from an HTML file?
 
Hi

Why do you obfuscate the posted code ?

Use forward slashes ( / ) in HTML documents.

Remove the single quotes concatenated to the PDFOption variable :
Code:
PDFWin=document.open(PDFURL,HTMLname,PDFOption)

You reversed your "JS content" and "test.htm content" comments. Is that only in your post, or in reality too ?

I understand that your JavaScript is in a separate file. In that case remove the hiding comments around the code.

Feherke.
 
Reply to Feherke, and thanks for the help!
1 I obfuscated the code because yesterday I was bombed off the forum four times, no reason given. So this morning I tried to eliminate all the red underlines in my message. I now see it wasn't necessary. Still don't know why I couldn't submit yesterday.
2 Hiding comments removed. (I copied this code from a friend, and don't know any of the rules of JavaScript.)
3 Concatenated single quotes removed.
4 You're right, I reversed the contents in my posting, but they are correct in my system.
===================================
Bottom line: the address is still wrong.
Seems to me that the anchor in test.htm points a message at the javascript in the distant folder. The javascript gets the address in the var PDFURL, but adds the indirect ../../ to it.
The line in test.htm now reads SRC="../../WEBPDF.JS
 
Hi

Hmm... I begin to have a feeling that your problem may be not JavaScript. If you insert a link like below and click it in the browser, are you getting the right file ?
Code:
<a href="/k/t/SAMPLE.PDF">use link</a>

Feherke.
 
Just tried that. Firefox gives a blank screen, Explorer doesn't respond at all--still shows test.htm.
 
Hi

So you have to debug that first. Then decorating the situation with JavaScript will also work.

I would like to help more, but for now I do not understand the situation with those paths. By the way, are you testing it through a web server, or just loaded directly from the harddisk ?

Feherke.
 
I'm developing a project on my hard drive, to be issued on a CD. Firefox and Explorer are being used from the hard drive.

A paragraph about me and my project, so you can help me better. I am 80 years old, have been programming since 1971 in QBASIC because it was free, and PROGRESS and another DBASE language when I could find work. Otherwise I was a pharmacist. I'm about 23 years into this project and it is nearly ready to distribute.
My project is large:
1056 folders
47,000 files
2.94 mb
est. 1.5 million links
It's all in HTML, self-taught and very limited.
My HELP file has graphics which I produced in PageMaker and printed in PDF, assuming that there would be a way to open a PDF file from an HTML file. When I suddenly discovered myself helpless to know how to do it, a friend sent me the following JavaScript file:
Code:
<!-- Hide the following from other browsers
function PDFOpen(PDFURL,PDFName)
{
var HTMLname = PDFURL.substring(0,6)
var PDFOption="toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no,fullscreen=yes'
PDFWin=document.open(PDFURL,HTMLname,"'"+PDFOption+"'")
PDFWin.moveTo(0,0);
PDFWin.resizeTo(screen.width,screen.height);
}
// Stop hiding JavaScript -->
I found that the substring(0,6) had to be changed to accept my "INTRO.PDF" or perhaps "HELP.PDF" filename (0,5 or 0,4) respectively.
I wonder re the first PDFWin line without end semicolon.
I've been remodeling the HELP file to have internal links so the user can click to the paragraph of interest. I know how to do that in HTML, so have reduced the size of the PDF file to three diagrams with lists of explained symbols, and I know how to open the PDF from the HTML file in the same folder. That is probably the correct solution to my problem.
The whole thing began when I found that the javascript and the PDF had to be in the same folder: that would mean adding 90,000 files to my system--easy to do but not elegant.
Now I see I can put the HTML HELP file and PDF diagram file in the same folder, \k. I can reach the HTML HELP file with a link in each of the 47,000 files wherever they are located, and the PDF file from that one. That's a better design because the user won't have to load Acrobat every time he wants help.
Of course I'm still curious how to open a PDF in a distant folder, but it isn't worth spending your time on any more. Again, thanks for your kind interest.
 
Hi

For now two more errors in that function :
Code:
function PDFOpen(PDFURL,PDFName)
  {
   var HTMLname = PDFURL.substring(0,6)
   var PDFOption=[red]'[/red]toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no,fullscreen=yes'
   PDFWin=[red]window[/red].open(PDFURL,HTMLname,PDFOption)
   PDFWin.moveTo(0,0);
   PDFWin.resizeTo(screen.width,screen.height);
  }
By the way, the quote was correct in your first post...

By the way, the oldest guy doing the webmaster is only 77 old. You are tough.

Feherke.
 
Hi

Previously I want to say : " By the way, the oldest guy I know doing the webmaster is only 77 old. You are tough."

Got it. Explorer requires valid identifier for the target name, while you have :

PDFURL='/k/t/SAMPLE.PDF'
HTMLname='/k/t/S'

So those slashes ( / ) are the problem. So the function with the final modification :
Code:
function PDFOpen(PDFURL,PDFName)
{
  var HTMLname = PDFURL[red].replace(/\W/g,'')[/red].substring(0,6);
  var PDFOption='toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no,fullscreen=yes';
  PDFWin=window.open(PDFURL,HTMLname,PDFOption);
  PDFWin.moveTo(0,0);
  PDFWin.resizeTo(screen.width,screen.height);
}
But you can use that line without [tt]substring()[/tt] :
Code:
  var HTMLname = PDFURL[red].replace(/\W/g,'')[/red];

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top