2012-06-25 1 views
0

Google 문서 및 다운로드 링크가있는 페이지가 있습니다 (아래의 인조 예). 링크를 클릭하면 iframe이 회색으로 바뀌고 다시 돌아 오지 않습니다. 페이지를 오른쪽 아래로 벗겨 냈으므로이 두 요소 만 있고 여전히 발생합니다.다운로드 링크를 클릭하면 iframe의 Google 문서가 회색으로 바뀝니다.

Firefox, Chrome, Safari에서 확실히 발생합니다.

Google 문서가없는 iframe에는이 문제가없는 것 같습니다.

아이디어가 있으십니까?

<html> 
<head></head> 
<body> 
<iframe src="http://docs.google.com/document/d/1mCYGLa8-Qsz_nYdk_f_8YefqWKMyulwVl223rebRMqM/preview" width="660" height="648"></iframe> 
<a class="download_link" href="http://fastdl.mongodb.org/osx/mongodb-osx-i386-2.0.6.tgz">Download</a> 
</body> 
</html> 

답변

0

불쾌한 해결책은 링크 태그에 target='_blank'을 설정하는 것입니다. 이렇게하면 별도의 창에서 요청이 열리지 만 요청이 다운로드로 등록되면 창이 닫히고 새 다운로드가있는 원본 페이지가 백그라운드로 남습니다.

이것은 Chrome과 Firefox에서 잘 작동하는 것으로 보이지만 Safari는 다운로드가 진행되는 동안 새 창을 엽니 다.

다른 해결책은 iframe 설정을 src 속성을 자체로 설정하여 다시로드하는 것입니다. 유일한 문제는 사용자가 스크롤 위치를 잃어 버리는 것입니다.

하이브리드 솔루션을 선택했으나 Chrome과 Firefox의 모든 버전에서 동일한 동작 (다운로드 시작시 탭 닫음)이 발생한다는 대규모 가정을 수행했습니다. 아마도 브라우저 검색이 잘 정제되어야하므로 잘못된 것입니다.

또는, 헤이, 구글이 고칠 수 구글 문서 도구 :

 // preserve the google doc in the iframe. else the iframe goes gray when a download link is clicked 
     if (navigator.userAgent.indexOf('Chrome') != -1 || navigator.userAgent.indexOf('Firefox') != -1){ 
      // Chrome and Firefox open new tabs with target='_blank' but close them again when the download begins 
      // the page itself is unaffected 
      $('a.download_link').attr('target', '_blank'); 
     } 
     else{ 
      // the above doesn't work on Safari and probably others so fall back to reloading the iframe contents 
      $('a.download_link').live('click', function(){ 
       $('iframe').each(function(id, frame){ 
        frame.src = frame.src; 
       }); 
      }); 
     } 
관련 문제