The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. October 11, 2008, 02:11:36 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: IE6 PDF Download onClick & window.open bug workaround  (Read 418 times)
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 5011


Stars & Stripes! STARS & FRAGGIN STRIPES MAN!


View Profile
« on: June 15, 2008, 03:55:19 PM »

Jeepers this has to be one of the kludgiest workarounds I've seen in a while.

While working through some issues on a site I noticed that if I have an HREF pointing to a PDF file it opens fine in IE6, but if I use window.open in the onClick of a button, IE reports that "The website is not available at the moment, try again." Uh huh.

After boatloads of testing to make sure that it worked in every other frigging browser in creation (including IE7) it became clear that I needed a workaround. Here it is: I created a input-less form at the bottom of my page inside of a non-displaying div thus:

<div style="display: none;"><form id="testform" method="GET" target="_blank"></form></div>

note also that the method of the form is GET. In the button I call my own submit function thus:

<input type="button" value="Click here to get it!" onClick="openPDF('/pdfs/thePDF.pdf');">


I handle the function like this: pushing the URL I want to open into the action of the form and submitting it:

Code:
<script>
function openPDF(theURL)
{
var target = document.getElementById('testform');
target.action = theURL;
target.submit();
}
</script>

Works like a charm in all browsers, including IE 6  Angry

/perk
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!