Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET4.0
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 3-Oct-12 21:17pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Following code resolved my issue
 
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 Smile | :)
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid