Solved

popup not working

Posted on 2011-03-22
16
320 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
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.
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now