Click here to Skip to main content
15,884,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,
I'm using iframe to download files using following jquery

function shwAtt(strPath) {
	        //document.getElementById("<%= hdnPath.ClientID%>").value = strPath;
	        //document.getElementById('frmAttachment').submit();
	        
	        var iframe;
	        iframe = document.getElementById("hiddenDownloader");
	        if (iframe == null) {
	            iframe = document.createElement('iframe');
	            iframe.id = "hiddenDownloader";
	            iframe.style.visibility = 'none';
	            document.body.appendChild(iframe);
	        }
	        iframe.src = strPath;   
	        return false;
	    }


It works fine but when it come to text file, it does not open as an attachment but the text inside the document is displayed in iframe.

Any anyone tell how can open text file as popup which ask user to save/open rather
than displaying inside the iframe

Thanks in advance
Posted

1 solution

Following code resolved my issue

C#
function shwAtt(strPath) {
           var varExt = strPath.split('.');
           //alert(varExt.length);
           if (varExt[varExt.length - 1] == "txt") {
               window.open(strPath);
           }
           else {
               var iframe;
               iframe = document.getElementById("hiddenDownloader");
               if (iframe == null) {
                   iframe = document.createElement('iframe');
                   iframe.id = "hiddenDownloader";
                   iframe.style.visibility = 'hidden';
                   document.body.appendChild(iframe);
               }
               iframe.src = strPath;
           }
           return false;
       }


Happy coding :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900