You are viewing limited content. For full access, please sign in.



HOWTO: Force all electronic files to open using ElectronicFile.aspx

posted on August 23, 2023

The following code will modify all electronic file links, such as PDF documents, to open using ElectronicFile.aspx instead of DocView.aspx in Laserfiche WebLink 11.x

1. Open Browse.aspx in a text editor, copy the code below and paste it right above the </body> element.

(function() {

    var proxied = window.XMLHttpRequest.prototype.send;
	var sent = false;
    window.XMLHttpRequest.prototype.send = function() {
		sent = true;
        var pointer = this
        var intervalId = window.setInterval(function(){
			console.log('Ready State: ' + pointer.readyState);
                if(pointer.readyState != 4){
				sent = false;			

        }, 1);
        return proxied.apply(this, [];
	// After initial load, observe the table that contains the links for any additions due to scrolling
	var t = document.getElementsByClassName('p-datatable-table')[0];
	var observer = new MutationObserver(entryname_column_changes);
	observer.observe(t, {
		attributes: false,
		childList: true, // report added/removed nodes
		subtree: true,   // observe any descendant elements


function entryname_column_changes(mutations){
  for (let mutation of mutations) {
    if (mutation.type === 'childList') {

function transform_links() {

    //Obtain the EntryNameColumn cells in the browse table and loop through them after a slight delay
    $(".EntryNameColumn").delay(500).each(function () {
        // Find all A elements
		$(this).find("a").each(function() {
			// Get all a elements that have a class value of ElectronicFileIcon
			var ef = $(this).find("div.ElectronicFileIcon");
			// console.log($(this).attr("href"));
			// console.log(ef.length);
			if(ef.length == 1){
				// Get the existing URL
				var old_url = $(this).attr("href");
				// Transform links that have not already been processed
					// Create a new URL based upon the old one
					var new_url = old_url.replace("DocView","ElectronicFile").replace("?id=","?docid=");
					// Replace old URL with our new one
					// Clone the content which removes all existing event handlers
					var b = $(this).clone();
					// Replace existing content with the clone content which will allow the ElectronicFile link to work.

2. Save browse.aspx and refresh the page. All of the electronic file links should now open directly.

Hope this helps!

Wesley Funderberg

7 0
replied on May 10

Well that just saved me a lot of time! Thank you.

0 0
replied on February 22 Show version history


Thanks for sharing.

This works great when browsing the the Repository and Clicking on an Entry if I click a PDF it will automatically convert to ElectronicFile.aspx.

It does not seem to work when passing a URL Link. It does not automatically detect an Electronic Document, use ElectronicFile.aspx and download.

If I pass a URL it does not automatically change to ElectronicFile.aspx.

The idea being docview.aspx is used from a Web application which might be a Laserfiche Standard, PDF or Excel. WebLink 9 just automatically detects and handles when using below to automatically download the file.

0 0
replied on February 22


 You are correct about it not working if a URL is passed to Laserfiche as it's only manipulating the links on the client side. After WebLink 9, Laserfiche made major changes to the back-end which forced all documents to go through DocView.aspx.


0 0
replied on February 23

Thanks so much for your post and subsequent follow up.

The confirmation helps a great deal.

0 0
replied on February 1

I implemented this in our test bed and it did indeed download the file with just a click but did not prompt me to open it. I had to click on it in the download folder to open it.

I think part of the problem might be that the file does not have an extension which is why I'm looking into something like this in the first place.

If I could get it to give the user the 'How do you want to open this file?' prompt with a click on the link, I would be thrilled.

0 0
replied on February 22


 That is browser independent on how it handles files that a user clicks on.

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.