Opening file types without opening new page
Friday, March 24, 2006 1:25:17 AM
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
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.
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.

Maverickmav1976 # Sunday, March 26, 2006 11:22:37 AM
thank you for this script.
Markus Liebeltmliebelt # Thursday, May 4, 2006 9:34:04 AM
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
dapxin # Thursday, April 2, 2009 4:33:05 AM
dapxin # Saturday, January 2, 2010 11:00:30 AM
-also, does it slow pages down per chance ?
Lee HarveyLee_Harvey # Saturday, January 2, 2010 2:08:38 PM
!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
Bryan KirkZero3K # Sunday, January 17, 2010 11:36:20 PM
Lee HarveyLee_Harvey # Monday, January 18, 2010 12:57:24 AM
!href.match(/\.exe$/) &&
!href.match(/\.zip$/) &&
...just after the .doc line.
Bryan KirkZero3K # Monday, January 18, 2010 2:42:24 AM
Lee HarveyLee_Harvey # Monday, January 18, 2010 2:42:26 PM
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
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
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
Lee HarveyLee_Harvey # Tuesday, January 19, 2010 2:14:19 AM
dapxin # Tuesday, September 6, 2011 6:19:57 AM
Do you still find a need for it ?
Lee HarveyLee_Harvey # Tuesday, September 6, 2011 12:43:35 PM