사용자가 다운로드 할 수있는 문서에 링크 된 체크 상자가 있습니다. 나는 여기에 도착한 일부 코드를 해킹했다.체크 박스를 기반으로 한 파일 다운로드
지금까지 downloadChecked 함수가 의도 한대로 작동하지만 makFrame 함수가 제대로 실행되지 않는 것 같습니다. 지금은 아무 것도하지 않는 것 같습니다.
function makeFrame(url)
{
ifrm = document.createElement("IFRAME");
ifrm.setAttribute("style", "display:none;") ;
ifrm.setAttribute("src", url) ;
ifrm.style.width = 0+"px";
ifrm.style.height = 0+"px";
document.body.appendChild(ifrm) ;
}
function downloadChecked()
{
for(i = 0 ; i < document.downloadform.elements.length ; i++)
{
foo = document.downloadform.elements[ i ] ;
if(foo.type == "checkbox" && foo.checked == true)
{
makeFrame('somefile.do?command=download&fileid=' + foo.name);
}
}
}
하고 함수 내에서
ifrm = document.createElement("IFRAME");
를 선언 해당 HTML
<form name="downloadform">
<input type="checkbox" name="file" id="file1"
value="file source etc" />
<input type="checkbox" name="file" id="file2"
value="file source etc" />
<input type="button" value="Download all" onClick="downloadChecked();" />
오류가 있는지 개발자/디버깅 도구를 확인하십시오. 그것은 우리가 당신의 기능이 실패한 시점을 결정하는 데 도움이 될 것입니다. Firefox를 사용하는 경우 [Firebug] (http://getfirebug.com/)를 사용하는 것이 좋습니다. IE9 +를 포함한 모든 최근 시장 브라우저에는 개발자 도구가 내장되어 있습니다. – Kiruse
다운로드 처리기 "somefile.do"가 파일의 적절한 헤더를 설정합니까? – Michal