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


mav1976 # 26. March 2006, 11:22
thank you for this script.
mliebelt # 4. May 2006, 09:34
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
wunage # 2. October 2007, 16:14
dapxin # 2. April 2009, 04:33