Prepare!

Lee Harvey's Zombie Hit Parade

Opening file types without opening new page

, , , ,

For those of you who hate to see a "Blank page" appear when clicking links for certain file types, I present the following User JavaScript file...

Download/view pdfHandler.js
document.addEventListener("load",
  function(e) {
    if (!document.body) document.body = document.getElementsByTagName("body")[0];
    if (!document.body) return;
    if (!document.links) return;
    for (var i = 0; i < document.links.length; i++) {
      var href = document.links[ i ].getAttribute("href");
      if (!href) continue;
      if (!href.match(/\.pdf$/) &&
          !href.match(/\.doc$/) &&
          !href.match(/\.xls$/))
          continue;

      if (!document.blankIframeHandler) {
        document.blankIframeHandler = document.createElement("iframe");
        with (document.blankIframeHandler) {
          setAttribute("src", "about:blank");
          setAttribute("id", "blankIframeHandler");
          setAttribute("name", "blankIframeHandler");
          setAttribute("style", "display:none;visibility:hidden;");
        }
        document.body.appendChild(document.blankIframeHandler);
      }
      document.links[ i ].setAttribute("target", "blankIframeHandler");
    }
  }, false);


This User JavaScript creates a hidden inline frame (iframe element) on the current page, then targets all .pdf, .doc, and .xls links to open inside that hidden inline frame.

This technique seems fairly effective at opening file types with associated programs in Opera, such as .pdf files for Adobe Reader.

Enjoy.

My new addition to the familyA simple cross-browser technique to block potentially harmful websites

Comments

Maverickmav1976 Sunday, March 26, 2006 11:22:37 AM

Hi Lee,

thank you for this script. up

Markus Liebeltmliebelt Thursday, May 4, 2006 9:34:04 AM

Hi Lee,

do you have an idea how to adapt that scheme to hide the emtpy page when selecting an attachment in a mail? Currently, I get the empty page. When I test it with an HTML file with embedded link, your solution works as expected.

Bye Markus

Alexwunage Tuesday, October 2, 2007 4:14:24 PM

Good job. happy

dapxin Thursday, April 2, 2009 4:33:05 AM

thx

dapxin Saturday, January 2, 2010 11:00:30 AM

can this be made to work also with . rar files from rapidshare links ?smile


-also, does it slow pages down per chance ?

Lee HarveyLee_Harvey Saturday, January 2, 2010 2:08:38 PM

Most likely, yes. Just add:

!href.match(/\.rar$/) &&

...after the .doc line. If you only want it for rapidshare, then save the script as a site-specific UserJS script.

dapxin Saturday, January 2, 2010 2:46:41 PM

thx. I already did that. just wanted to b sure smile

Bryan KirkZero3K Sunday, January 17, 2010 11:36:20 PM

It doesn't work on the download page for a program that's listed on Softpedia.com.

Lee HarveyLee_Harvey Monday, January 18, 2010 12:57:24 AM

Most of the downloads on softpedia.com are not .pdf, .doc, or .xls -- for which this script was intended. To make it work for .exe and .zip downloads, add:

!href.match(/\.exe$/) &&
!href.match(/\.zip$/) &&

...just after the .doc line.

Bryan KirkZero3K Monday, January 18, 2010 2:42:24 AM

well, that's what I did. But, it doesn't do anything (the link to the program on the download page creates a blank tab).

Lee HarveyLee_Harvey Monday, January 18, 2010 2:42:26 PM

I just noticed that my download link above needed to be updated. It now points to the correct script location.

Anyhow, after I added the two lines to the script in order to support .exe and .zip files, I can download files from softpedia.com without it creating a new _blank window.

What (URL) are you trying to download from softpedia.com?

Also, while visiting softpedia.com in Opera, if you right-click on their page and select "Edit Site Preferences...", goto the "Scripting" tab, is the pdfHandler.js script located in the "User JavaScript Folder" location? If not, please update the folder location, reload the page, and retry.

Hope that helps.

Bryan KirkZero3K Monday, January 18, 2010 11:11:20 PM

http://www.softpedia.com/progDownload/BitTorrent-Ultra-Accelerator-Download-128995.html

Yes, its in the directory that is shown in the Scripting tab in its Site Preferences.

Btw, I'm using the latest pre-alpha build of Opera v10.50.

Lee HarveyLee_Harvey Monday, January 18, 2010 11:49:16 PM

Sorry, I don't support pre-alpha, alpha, pre-beta, or beta builds. Once 10.50 ships to production, then I'll update the script (if necessary), but not before.

Try using this UserJS script with production version 10.10, and I think you'll be happy.

Enjoy.

Bryan KirkZero3K Tuesday, January 19, 2010 2:03:04 AM

Hmm, so what about the link? Does the script work there? Regarding using it with v10.10, I'm not that concerned about one site not working with the script. So, I'll continue to use it in the pre-alpha I'm using.

Lee HarveyLee_Harvey Tuesday, January 19, 2010 2:14:19 AM

Yes, the download file (referenced by the softpedia.com link) opens fine (w/o blank page) in 10.10.

dapxin Tuesday, September 6, 2011 6:19:57 AM

would this still be useful for the latest 11v of Opera ?

Do you still find a need for it ?

Lee HarveyLee_Harvey Tuesday, September 6, 2011 12:43:35 PM

Perhaps for some flaky sites; but overall, no, not so much anymore.

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.