2011-04-21 3 views
1

HTML 코드 :JQuery와 변화에 대한 이벤트 파일 다운로드

<span>Download Report as</span> 
    <select id="comboFile"> 
     <option value="none">Select</option> 
     <option value="http://somewhere/123.pdf">PDF</option> 
     <option value="http://somewhere/123.csv">CSV</option> 
    </select> 

JQuery와 :

$(document).ready(function() { 
     $("#comboFile").change(function() { 
     if ($(this).val() != "none") GetFile($(this).val()); 
     $(this).val("none"); 
    }); 
}); 

function GetFile(fileURL){ 
///Code to be filled 
//window.location.href = fileURL;///Does not seem to work for new window 
} 

나는 .. 나는 파일 다운로드를 개시 할 .. 내가 코드를 입력 할 필요가 얼마나 꽤 많이 붙어 파일 가져 오기 기능 ...

+0

코드는 주어진대로 작동합니다. 'window.location' 설정은 http://jsfiddle.net/XeAzy/에서 가능합니다. 'window.location'을 설정 한 후에 작성된 JavaScript는 실행되지 않습니다. –

+0

"작동하지 않는 것 같습니다"를 정의하십시오. –

+0

죄송합니다. 나는 나쁜 창에서 말하기로되어있었습니다. 그것은'window.location.href = fileURL'로되어있었습니다. –

답변

0
$(document).ready(function() { 
     $("#comboFile").change(function() { 
     if ($(this).val() != "none") GetFile($(this).val()); 
     $(this).val("none"); 
    }); 
}); 

function GetFile(fileURL){ 
///Code to be filled 
//window.open(fileURL); 
} 
+0

고마워요, 그러면 새 창이 열립니다. 나는 그것을 다운로드하고 싶다. –

+0

아, 알겠습니다. 이 경우 PHP를 작성해야합니다. 본질적으로, 당신은 http://myserver.com/download.php?file=myfile.pdf 과 같은 것으로 윈도우의 위치를 ​​설정했다. 그런 다음 헤더를 설정하고 PHP의 readfile() 함수를 사용해야한다. 자세한 내용이 담긴 게시물이 많이 있어야합니다. –