views:

341

answers:

3

Here's the problem, which only occurs in Internet Explorer (IE). I have a page that has links to several different types of files. Links from these files execute a Javascript function that opens a new window and loads the specific file. This works great, unless the file I need to open in the new window is a PDF in which case the window is blank, even though the URL is in the address field. Refreshing that window using F5 doesn't help. However, if I put the cursor in the address field and press <enter> the PDF loads right up.

This problem only occurs in IE. I have seen it in IE 7 and 8 and am using Adobe Acrobat Reader 9. In Firefox (PC and Mac) everything works perfectly. In Chrome (Mac), the PDF is downloaded. In Safari (Mac) it works. In Opera (Mac) it prompts me to open or save. Basically, everything probably works fine, except for IE.

I have searched for similar problems and have seen some posts where it was suggested to adjust some of the Internet Options on IE. I have tried this but it doesn't help, and the problem wasn't exactly the same anyway.

Here's the Javascript function I use to open the new window.

function newwin(url,w,h) {
   win = window.open(url,"temp","width="+w+",height="+h+",menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=auto,resizable=yes");
   win.focus();
}

You can see that I pass in the URL as well as the height, h, and width, w, of the window. I've used a function like this for years and as far as I know have never had a problem.

I call the newwin() function using this.

<a href="javascript:newwin('/path/document.pdf',400,300)">document.pdf</a>

(Yes, I know there are other, better ways than using inline JS, and I've even tried some of them because I've run out of things to try, but nothing works.)

So, if anyone has an idea as to what might be causing this problem, I'd love to hear it.

+3  A: 

try:

function newwin(url,w,h) {
     var win = window.open("","temp","width="+w+",height="+h+",menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=auto,resizable=yes");
     win.location.href = url;
     win.focus();
}
David Murdoch
@David - I had a similar problem, after applying your solution, the pdf now renders perfectly fine. Could you please explain how this works? Is it the zone or some security? Why doesn't it work when i use only window.open ?
SoftwareGeek
I'm pretty sure it is just a bug in IE's implementation (as usual). If it was a security issue then it wouldn't work at all.
David Murdoch
+1  A: 

1st try this:

function newwin(url,w,h) { 
   win = window.open(url,"temp","width="+w+",height="+h+",menubar=yes,toolbar=yes,location=yes,status=yes,scrollbars=auto,resizable=yes"); 
   win.focus(); 
   return false;
}

-

<a href="#" onclick="return newwin('/path/document.pdf',400,300);">document.pdf</a>

If this does not solve the issue it should be simply useless IE securtiy settings that as usual does everything to jeopardize web development and web experience with the excuse of security concern (this is only my personal opinion).

Try then adding the website/webpage to IE TRUSTED sites: Tools - Internet Options - Security - Trusted Sites (and click Sites button and add the site).

Marco Demajo
A: 

Marco: Thank you, but I had tried some very similar things with no luck.

However, David, you solution did the trick! THANK YOU!

Dean
you should mark my answer as an accepted answer then.
David Murdoch