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.
