window.onbeforeunload가 iPad에서 작동하지 않습니까?
onbeforeunload
이벤트가 iPad에서 지원되는지 및 / 또는 사용하는 다른 방법이 있는지 아는 사람이 있습니까?
나는 거의 모든 것을 시도했으며 onbeforeunload
이벤트가 iPad (Safari 브라우저)에서 트리거되지 않는 것 같습니다 .
특히, 이것은 내가 시도한 것입니다.
window.onbeforeunload = function(event) { event.returnValue = 'test'; }
window.onbeforeunload = function(event) { return 'test'; }
- (위의 두 가지 모두 함께)
window.onbeforeunload = function(event) { alert('test')'; }
- (위의 모든 기능이 있지만 내부
<body onbeforeunload="...">
이 모든 것이 PC의 FF 및 Safari에서 작동하지만 iPad에서는 작동하지 않습니다.
또한 페이지를로드 한 직후 다음을 수행했습니다.
alert('onbeforeunload' in window);
alert(typeof window.onbeforeunload);
alert(window.onbeforeunload);
각각의 결과는 다음과 같습니다.
true
object
null
따라서 브라우저에는 속성이 있지만 어떤 이유로 시작되지 않습니다.
페이지를 벗어나는 방법은 뒤로 및 앞으로 버튼을 클릭하고 상단 표시 줄에서 Google 검색을 수행하고 주소 표시 줄에서 위치를 변경하고 북마크를 클릭하는 것입니다.
무슨 일이 일어나고 있는지 아는 사람이 있습니까? 어떤 의견이라도 대단히 감사하겠습니다.
감사
onunload () 이벤트가 발생한다는 것을 발견했습니다. 행동이 다소 이상합니다. 이벤트에 연결된 콜백 함수에있는 모든 것은 실제로 새 페이지가 백그라운드에서로드 된 후에 실행됩니다 (아직로드되었음을 알 수는 없지만 서버 로깅에 표시됨).
더 이상하게도 onunload ()에 confirm () 호출이 있고 사용자가 링크를 클릭하여 다른 곳으로 이동했다면 비즈니스에있는 것입니다. 그러나 사용자가 iPad Safari 브라우저 탭을 닫으면 onunload () 이벤트가 발생하지만 confirm ()은 응답으로 암시 적 취소를 갖습니다.
이 자바 스크립트는 데스크톱 / 노트북 / 기타 브라우저뿐만 아니라 ipad 및 iphone의 Safari와 Chrome에서도 작동합니다.
var isOnIOS = navigator.userAgent.match(/iPad/i)|| navigator.userAgent.match(/iPhone/i);
var eventName = isOnIOS ? "pagehide" : "beforeunload";
window.addEventListener(eventName, function (event) {
window.event.cancelBubble = true; // Don't know if this works on iOS but it might!
...
} );
Apple만이 확실히 알 수 있지만, 제 생각에는 모바일 Safari에서 해당 기능을 의도적으로 활성화하지 않은 것 같습니다.
있다 웹킷에서 알려진 버그 onbeforeunload와 함께. 나는 그것이 Chrome 5의 최신 베타에서 수정되었다고 생각하지만, iPad의 브라우저가 수정되지 않은 WebKit 버전으로 만들어 졌을 가능성이 높습니다.
beforeunload 이벤트는 Mobile Safari에서 지원되지 않습니다. 지원되는 모든 이벤트 목록은 여기에서 확인할 수 있습니다. 이벤트 처리 Apple 문서
그리고 beforeunload는 목록에 없습니다!
https://code.google.com/p/chromium/issues/detail?id=97035
들으십시오.
페이지 닫기 이벤트 (beforeunload, unload, pagehide) 중에 더 이상 경고가 허용되지 않습니다.
경고, 프롬프트, 확인 및 이와 같은 기타 작업도 더 이상 허용되지 않는다고 생각합니다.
If you just need to know if the page has been left you can use document.unload
. It works fine in ios browsers. If you see on Apple documentation you'll find that it's deprecated and they recommend to use document.pagehide
Here's a solution that should work on all modern browsers:
var unloaded = false;
window.addEventListener("beforeunload", function(e)
{
if (unloaded)
return;
unloaded = true;
console.log("beforeUnload");
});
window.addEventListener("visibilitychange", function(e)
{
if (document.visibilityState == 'hidden')
{
if (unloaded)
return;
unloaded = true;
console.log("beforeUnload");
}
});
Mobile browsers don't tend to not support beforeunload
because the browser can go into the background without unloading the page, then be killed by the operating system at any time.
Most desktop browser contain a bug that causes visibilityState
to not get called when the document unloads. See: here.
Therefore, it's important to include both events to cover all scenarios.
NB
I have used console.log
instead of alert
in my example because alert
will get blocked by some browsers when called from beforeunload
or visibilitychange
.
참고URL : https://stackoverflow.com/questions/3239834/window-onbeforeunload-not-working-on-the-ipad
'Program Tip' 카테고리의 다른 글
Corona SDK의 타일을 한 단어로 결합하여 Breakout 게임 그리드를 만드시겠습니까? (0) | 2020.10.17 |
---|---|
Visual Studio 2010을 더 빠르게 만들기위한 성능 팁? (0) | 2020.10.17 |
Ctrl + A와 Ctrl + Shift + A를 다르게 매핑하는 방법은 무엇입니까? (0) | 2020.10.17 |
스칼라의 믹스 인 vs 컴포지션 (0) | 2020.10.17 |
memtrack 모듈을로드 할 수 없습니다. Logcat 오류 (0) | 2020.10.17 |