Click here to Skip to main content
12,304,884 members (66,470 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET4
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100