我正在爲Android和iPhone製作網絡應用程序。我的問題是,我想刷新網頁,當用戶去風景。由於我是JavaScript的初學者,我不知道該怎麼做。請幫我使用方法當用戶將手機變爲風景時刷新網頁
回答
您可以使用orientationchange jQuery Mobile的事件,然後做一個
window.location.reload();
刷新頁面。
例如:
$(function(){
// Set Inital orientation
// get the initial orientation from window which
// returns 0 for portrait and 1 for landscape
if(window.orientation == 0){
var ori = "portrait";
}else{
var ori = "landscape";
}
changeOrientation(ori);
// Orientation Change
// When orientation changes event is triggered
// exposing an orientation property of either
// landscape or portrait
$('body').bind('orientationchange',function(event){
changeOrientation(event.orientation)
})
// Change the style dependengt on orientation
function changeOrientation(ori){
// Remove all classes separated by spaces
$("#orientation").removeClass('portrait landscape');
$("#orientation").addClass(ori);
$("#orientation").html("<p>"+ori.toUpperCase()+"</p>");
}
});
@yuzi我已經更新了我的代碼,但我建議你看看我n到jquery和jQuery的手機(這個例子是使用) – Johan 2012-01-13 10:03:38
終於我做到了這一點, 然後它的工作 「window.onorientationchange = function(){ var orientation = window.orientation; 開關(方向){ case 0: window.location.reload(); 休息; case 90: window.location.reload(); 休息;案例-90: window.location.reload(); 休息; } }「 thanks Johan – FreshBits 2012-01-14 04:00:24
你可以使用一個計時器並定期檢查:
if (window.innerHeight > window.innerWidth) {
// Redirect code, window.location...
}
如果高度>寬度,手機將處於肖像模式,而不是風景 – Johan 2012-01-13 09:50:59
- 1. 使用python/flask刷新用戶網頁
- 2. 請求用戶限時刷新網頁
- 3. 當用戶刷新網頁時防止表單提交
- 4. 當使用scrollTo ListView不刷新,但手動滾動時刷新
- 5. 使用jQueryUI的手風琴,當它變爲新的 「窗格」
- 6. 將使用ModRewrite導致網頁刷新?
- 7. 當改變方向爲風景時使FlipperView全屏
- 8. 使用python刷新網頁
- 9. 當頁面刷新時使用javascript刷新塊內容
- 10. 使用jQuery手機版1.0rc3刷新listview
- 11. 當有人使用手機登錄時,將桌面網頁更改爲移動網頁
- 12. 刷新會話時間,當用戶確認保持聯機時
- 13. 手風琴錶行和刷新頁面後不變的錶行
- 14. 刷新時的手風琴抖動
- 15. 手機網絡應用程序 - 刷新時使用iPhone的問題
- 16. 用戶刷新頁面時加載不同的視頻背景
- 17. 當手機旋轉到風景時出現黑塊
- 18. 當從風景變爲肖像時,可以避免調用onCreate?
- 19. 使用pyserial刷新方法
- 20. 使用Google oAuth 2.0時刷新新用戶登錄頁面
- 21. 每當使用Javascript刷新頁面時,我如何讓網頁隨機生成一個新視頻?
- 22. jQuery Mobile刷新網絡手機的div
- 23. 當屏幕旋轉時,日誌,方法不起作用風景
- 24. javascript:history.go不刷新手機頁面?
- 25. 刷新頁面時用戶已註銷
- 26. 如何修復屏幕方向風景爲我的Windows手機
- 27. 將Cookie設置爲當用戶瀏覽網頁時過期
- 28. 在手機上使用Kendo ui網頁
- 29. 如何使用手機顯示網頁
- 30. 爲手機優化網頁
存在着這樣和答案的問題;) http://stackoverflow.com/questions/850472/how-do-i-detect-when-the- iphone-goes-into-landscape-mode-via-javascript-is- – matzino 2012-01-13 09:52:07
@ManseUK感謝U – FreshBits 2012-01-13 10:01:43
請關閉此問題以避免重複 – Murtaza 2012-01-13 10:12:21