2016-02-25 7 views
9

मेरे पास एक ऐसा एप्लिकेशन है जो डाउनलोड के लिए कुछ स्थिर फाइलें दिखाता है। यह एप्लिकेशन एक छिपी हुई आईफ्रेम बनाता है और स्रोत को फ़ाइल-यूआरएल पर सेट करता है।window.open() का उपयोग किए बिना टास्कपेन ऐप में फ़ाइल कैसे डाउनलोड करें?

ब्राउज़र एक सहेजने वाला संवाद दिखाता है।

लेकिन माइक्रोसॉफ्ट ऑफिस के भीतर कोई सहेजने वाला संवाद नहीं है और दायर किया गया लोड शुरू नहीं हुआ है।

फ़ाइल Content-Disposition: Attachment के साथ परोसा जाता है। कामकाजी समाधान बस एक नया ब्राउज़र उदाहरण खोल देगा और फ़ाइल डाउनलोड ट्रिगर करेगा। मैं एक नई खिड़की नहीं खोलना चाहता जो फोकस हासिल करेगी।

<!DOCTYPE html> 
<html> 
    <head> 
     <script> 
      function di(){ 
       document.getElementById("d").src="blob.dat"; 
      } 
     </script> 
     <title>download</title> 
    </head> 
    <body> 
     <h1>file loading</h1> 
     <h2>works</h2> 
     <p>But opens a new window</p> 
     <a href="blob.dat" target="_blank"> a blank </a><br> 
     <a href="blob.dat" target="download"> named frame </a> 
     <h2>won't work</h2> 
     <a href="blob.dat"> a self </a><br> 
     <a href="blob.dat" target="_self"> a self </a><br> 
     <a href="blob.dat" target="_top"> a top </a><br> 
     <a href="#" onclick="di();"> iframe </a><br><br> 
     <iframe id="d"></iframe> 
    </body> 
</html> 

मुझे लगता है कि यह एक serius बग है अगर एक वेब आवेदन लिंक का अनुसरण unablle है।

उत्तर

0
<script language="javascript"> 
function OpenADocument(strDoc) 
{ 

     document.blob.hidFLID.value=strDoc; 
     document.blob.action = "OpenLinksDocument.asp"; 
     document.blob.method="post" 
     document.blob.submit(); 
} 
</script> 

---- एएसपी कोड ----

Private Sub DownloadFile(file, MainFileName) 
    '--declare variables 
    Dim strAbsFile 
    Dim strFileExtension 
    Dim objFSO 
    Dim objFile 
    Dim objStream, FileNM 
    strAbsFile = Server.MapPath(file) 
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject") 
    If objFSO.FileExists(strAbsFile) Then 
     Set objFile = objFSO.GetFile(strAbsFile) 
     strFileExtension = LCase(objFSO.GetExtensionName(file)) 

     '-- first clear the response, and then set the appropriate headers 
     Response.Clear 

     '-- the filename you give it will be the one that is shown ' to the users by default when they save 

     dim NewFileName 
    NewFileName= "RandomFileNameYouWishtoGive" & Session.SessionID &"." &strFileExtension 

     Response.AddHeader "Content-Disposition", "attachment; filename=" & NewFileName 
     Response.AddHeader "Content-Length", objFile.Size 
     Response.ContentType = "application/octet-stream" 

     Set objStream = Server.CreateObject("ADODB.Stream") 
     objStream.Open 
     '-- set as binary 
     objStream.Type = 1 
     Response.CharSet = "UTF-8" 
     '-- load into the stream the file 
     objStream.LoadFromFile(strAbsFile) 
     '-- send the stream in the response 
     Response.BinaryWrite(objStream.Read) 
     objStream.Close 
     Set objStream = Nothing 
     Set objFile = Nothing 
    Else 'objFSO.FileExists(strAbsFile) 
     Response.Clear 
     Response.Write("No such file exists.") 
    End If 
    Set objFSO = Nothing 
End Sub 

स्पष्टीकरण:

1) पर आप पृष्ठ लिंक लंगर टैग में आपका फ़ाइल का नाम का उल्लेख न करें,

2) इसके बजाय कुछ एन्क्रिप्टेड कोड या एन्क्रिप्टेड फ़ाइल नाम को पास करें

3) उस पृष्ठ पर जहां आप फ़ाइल नाम पोस्ट कर रहे हैं, मूल्य छिपाने के लिए फॉर्म अनुरोध करें फ़ाइल आईडी - hidFLID

4) अब उस फ़ाइल का नाम उपयोग करें और उस फ़ाइल नाम को प्रतिक्रिया शीर्षलेख में जोड़ें।

5) यह नहीं दिखाया जाएगा आपके Actial फ़ाइल नाम दर्ज कोड here`me/फ़ाइल पथ

6) उदाहरण से ऊपर मैं निर्दिष्ट किया है क्लासिक एएसपी में है, यदि आप अपने वेब उल्लेख है - प्रौद्योगिकी, मैं करने के लिए मदद मिल सकती है उस टेक में कोड प्रदान करें।

संबंधित मुद्दे

 संबंधित मुद्दे