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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use javascript to open a pdf document automatically 1

Status
Not open for further replies.

920506

Programmer
Jun 13, 2003
201
US

Hi all,
I have asp program created a pdf file on the fly.
After the pdf file is created, I would like to open the pdf file automatically for user instead of click the link on the page. I tried, but it's not working, any clues?

My code is like this:
<HTML>
<HEAD>
<TITLE># Print Brochure</TITLE>
</HEAD>

<BODY>

<%
OrderID=Trim(Request.QueryString("orderID"))
PONumber=Trim(Request.QueryString("ponumber"))

FileName=CreatePrintDoc(PONumber, OrderID)

'create a link that the user can open the pdf file manually
Response.Write "<p>Your <b>PDF Print Enrollment Form " &FileName & "</b> can be download <A TARGET=""_new"" Href=""/E-Cert/SelectPrint/" & FileName & """>here</A></p>."

'try to use javascript to open the pdf file automatically
%>
<script language="JavaScript">
<!--
alert('/E-Cert/SelectPrint/<%=FileName%>');
alert('<%=FileName%>');
var newWindow = window.open('/E-Cert/SelectPrint/<%=FileName%>', '_blank');
newWindow.focus();
// -->
</script>
</BODY>

</HTML>
 
What happened actually? Popup blocker might block it. Is it that or something other than that happened?
 
You want it to open in a separate window? You don't have to use JavaScript to do this, you could use

Response.Redirect

But what I suspect is happening is that the script is firing off the new window before it's actually done building the PDF..... you may need to either sleep it for a few seconds, or watch for the file to be created server-side before spawning the new window.

Those are just some thoughts....



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Thank you both of you.
Yes, I already used Response.Redirect based on suggestion on ASP forum. It works perfectly.
I think Greg's sense is right. Maybe it tried to open before the document is created.

by the way, I disabled the Popup blocker already for the specific web site.

Betty
 
I need help with launching PDFs too.

I can successfully launch the PDF in a new window, but how do I go about checking for the existance of the file first by the file's URL? I don't want to attempt to open the PDF in a new window only for the user to see a Page cannot be found error. Thanks!
 
If you are creating the PDF server-side, you would need to do it on the script side....

In VBScript, for example, you would do a:

dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
File = objFSO.FileExists(pathname)
Set objFSO = Nothing

... if File=True then it exists, if File=False then it doesn't.

I know... this is a javascript forum... but I don't know how to do it server-side in javascript. ;)



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Sorry if my question is silly. I'm still learning this stuff.
but, what you're saying is that there is no way to check with client side javascript if a URL exists?

thanks!
 
You know, I'm sure there is.... I know theres a way to find out if a graphic exists....

It's probably going to be something about trying to load it, catching the error, sleeping for a few seconds, and trying to load it again.

Wish I had a piece of code off the top of my head to share, but I'm having a bad day.


Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top