반응형
■ 사파리에서 a href download가 안되는 경우
# a href download attribute doesn't working in latest safari
1. webview 다운로드 링크 안될 때
2. pywebview 다운로드 링크 안될 때
3. ios에서 다운로드 링크 안될 때
4. mac에서 다운로드 링크 안될 때
5. 사파리(safari)에서 다운로드 링크 안될 때
■ 소스코드
let _a = document.createElement('a');
_a.target = '_blank';
_a.href = _url;
document.body.appendChild(_a);
_a.click();
webview 또는 mac, ios, pywebview 에서 다운로드나 링크이동이 안되는 경우가 있다.
safari 기반이라면 당연히 안될것이고~!
링크이동이나 다운로드를 해야된다면 저런식으로 추가해주면 된다.
# MAC에서만 처리를 하고 윈도우는 그대로 하고 싶을 때.
■ 소스코드
let _osCheck = navigator.userAgent;
if(_osCheck.includes('Mac')) {
let _a = document.createElement('a');
_a.target = '_blank';
_a.href = _url;
document.body.appendChild(_a);
_a.click();
}else{
location.href = _url;
}
navigator.userAgent 해당 운영체제를 확인할 수 있다.
따라서 Mac 일때만 href 다운로드 처리를 다른 방식으로 해주고, 윈도우에서는 location.href 를 사용하도록 분기할 수 있다.
[keyword]
Safari location.href, 사파리 location.href, 자바스크립트 OS 체크, 자바스크립트 OS 확인, safari href, 사파리 href, ios href, javascript os 확인, 사파리 href 다운로드, safari download, safari href download, 사파리 href download, 모바일 safari href
반응형
'웹 개발' 카테고리의 다른 글
sessionStorage vs 전역변수 & Ajax 동기 통신 (0) | 2022.04.26 |
---|---|
[datatable] <tr>, <td>에 속성/스타일 추가하기 (0) | 2022.04.13 |
[choicesjs] select 값 초기화하기 choicesjs init , choicesjs 초기화 (0) | 2022.04.06 |
[자바스크립트] 페이지 떠날때 데이터 넘기기_ 페이지 이동 시 이벤트 (0) | 2022.02.26 |
Ajax 로딩바 구현하기_ 스프링, 장고,자바스크립트,ajax 로딩바, 프로그래스바 (0) | 2021.12.29 |
댓글