如何使用iframe下载附件 [英] how to download attachment using Iframe

查看:88
本文介绍了如何使用iframe下载附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,
我正在使用iframe使用以下jquery下载文件

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;
	    }



它可以正常工作,但是当涉及到文本文件时,它不能作为附件打开,但是文档中的文本显示在iframe中.

任何人都告诉如何打开文本文件作为弹出窗口,要求用户保存/打开而不是
而不是在iframe中显示

在此先感谢



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

推荐答案

以下代码解决了我的问题

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 :)


这篇关于如何使用iframe下载附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆