Hi all,

I hit a problem where opening a link on my page which triggers a file
download breaks the JSmol applet (jsmol-13.1.14b) in Chrome 23.0.1271.95 under
Linux Mint 13 (Maya). I do not know whether this problem exists on other
platforms/browsers. I also have a solution which works for me (below) but
thought I would share the problem in case this is something the devs wish
to look into and also to share the solution for anyone hitting the same
problem. Also, someone may point out if there is a simpler fix to mine
below / that I was doing something silly :-).

I'm doing the following:
 - The page includes a JSmol applet. Clicking on different icons on the
page loads different models into this applet (using a database and AJAX).
This works beautifully and I'm really happy with the results.
 - The page has links to download files from the database. The links have
the form
       <a href='?query=downloadfile&amp;ID=6&amp;download=gz'>...</a>
   Clicking on a link causes a page reload which reads the file from the
database and prints the following:
        Content-Type: application/x-gzip
        Content-Disposition: attachment; filename="somefilename"
        Content-Length: somelength

        [contents of file]

Because the new page is an attachment, the page does not visibly reload so
the user gets the usual file download dialog. However, the page load breaks
the JSmol applet, maybe due to garbage collection.

My solution to this was to use an iframe. First, I replaced the links with
ones as follows:
   <a id='PSELink-6' href=''>...</a>
Then I include the following in $(document).ready:
   $('[id^="PSELink-"]').click(function() {
      this_id = $(this).attr('id');
ID = parseInt(this_id.split('-')[1]);
  var iframe = document.createElement("iframe");
  iframe.src = 'http://my.server.com/mywebpage.py?query=downloadfile&amp;ID='
+ ID + '&amp;download=gz';
  iframe.style.display = "none";
  document.body.appendChild(iframe);
      return false; // prevent page reload
  });

Clicking on the link still triggers a file download but (I'm guessing since
the page does not reload) the JSmol applet continues to function.

Regards,
Shane
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Jmol-developers mailing list
Jmol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to