Solved

popup not working

Posted on 2011-03-22
16
322 Views
Last Modified: 2012-05-11
I have a webpage with a link to a file that the user can open.  If I try to open it in the same window, it works.  If I try to open it in a new window, it doesn't.  We're using IE8.  Why would I get different behavior when opening the very same file, but in a new window?

gary
0
Comment
Question by:garystark
  • 9
  • 6
16 Comments
 

Expert Comment

by:isthisused
ID: 35194927
popup blocker could cause this
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35194999
If the link actually calls JavaScript, which in turn loads the new page, it may well work when you click on it and let it load in the same window, but if you right-click and choose Open in New Window it would fail (because the new window doesn't have the JavaScript function that the link is trying to call).
0
 

Author Comment

by:garystark
ID: 35199036
After further study I need to revise this question.  The problem ONLY shows itself if the filename contains the # sign.

So this link works...
file://data/file123.pdf

But this link does not...
file://data/file#123.pdf

If, instead of loading in a new window (_blank) I load into the same window, both work.

gary
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35199412
No need to re-post, I think I've got it.

That's because the hash is interpreted by the browser as meaning "open the file data/file and go to the bookmark named 123.pdf."  The hash needs to be URI encoded (as %23) so the browser will interpret it as a character in the path, and not as the name of a bookmark in the file.

e.g.
<a href="file://data/file%23123.pdf"></a>

In classic ASP you can use Server.URLEncode (http://msdn.microsoft.com/en-us/library/ms525738(v=VS.90).aspx) to encode file names to make them safe for use in a URL; in ASP.Net HttpServerUtility.UrlEncode (or Server.UrlEncode) (http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.urlencode.aspx); on the client in JavaScript using the "escape()" function (http://msdn.microsoft.com/en-us/library/9yzah1fh(v=VS.94).aspx). Also make sure your URIs are well-formed, you can review http://en.wikipedia.org/wiki/File_URI_scheme for details.

Further, in my quick tests, "file://" URLs seem to only work for file types that Internet Explorer can natively display - like text, XML or HTML - but not file types that depend on a plugin, such as PDFs.  Also note that "file:///" URIs should be used only when accessing paths on the client, use "http://" URIs for files located on the web server.
0
 

Author Comment

by:garystark
ID: 35199444
tgerbert, thanks for the reply.  Let me give that a try and get back to you...

gary
0
 

Author Comment

by:garystark
ID: 35202575
tgerbert,

My file is a pdf.  You said that IE can only natively display XML or HTML files, but my code works just fine when I target the same window.  Opening it in a new window (_blank) is where it fails.  So I still don't see a solution to the problem.

gary
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35202682
I said in my tests, it may very well work in your environment.

Nevertheless, my comments regarding the hash mark, and it's need to be encoded, are still valid and have nothing to do with being able to display a PDF in-browser using a "file://" URI.

Did you try making sure that your URL is valid in the first place (see the Wikipedia article I linked to above), and making sure the URLs are properly encoded using one of the methods I referred to?

Are these PDFs on the web server, or on the client computer? Are you using JavaScript to open them? Are you using ASP.Net? Can you post some example code to recreate the problem?
0
 

Author Comment

by:garystark
ID: 35211063
tgerbert,

I still cannot get this to work, regardless of encoding.  So that you can actually see what I'm dealing with, I created a screen capture video showing the problem...

http://www.youtube.com/watch?v=B2laqpStX9U&hd=1

gary
0
 

Author Comment

by:garystark
ID: 35211169
What you will see in the above video:

I created three test links, the first is raw (no encoding), the second using the URLEncode function, and the third using the Replace command. Only the first link works. Further note that it only works if I load the file into the same window. When I try to load it into a new window, it fails (due to truncation at the # sign).
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35214139
Ah ha!  Now I get it. ;)

Seems Internet Explorer isn't handling "file:///" URLs correctly.  Instead of making your URL "\\server\share\test#file.pdf", using "file://server/c:/local/path/to/share/on/server/test%23file.pdf" might work.

Your best bet, though, will probably be to make the PDFs available via a web server, and use a standard "http://webserver/test%23file.pdf" URL.
0
 

Author Comment

by:garystark
ID: 35215619
tgerbert,

I'm off today, but will give your lastest suggestion a try on Monday.

thanks,
gary
0
 

Author Comment

by:garystark
ID: 35233326
tgerbert,

The alternate url approach didn't work.  And I am unable to take the webserver approach as I have no control over the target server in question (IIS is not even installed).

gary
0
 

Accepted Solution

by:
garystark earned 0 total points
ID: 35234008
Update...I managed to make it work.  My solution was to redirect to a temporary asp page (in a new window), which in turn does a response.redirect to the target PDF file.  I used a session variable to pass the filename (although I could probably have passed it on the url).  The code for calling the PDF looks like this:

response.redirect "file:" & session("filename")

Thanks for your help with this problem.  Not sure how to proceed with the point.  How about I split the point, half for tgerbert and half for myself?

gary
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35234298
Good idea, I was about to suggest something a little more involved. ;)

Accept your own response as the only answer.
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35234383
I think you got the points assignment backwards - http:#a35234008 should get the 500 points.
0
 

Author Closing Comment

by:garystark
ID: 35304292
Found my own workaround.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question