2012-01-13 14 views
5

मैं एंड्रॉइड और आईफोन के लिए एक वेब एप्लिकेशन कर रहा हूं। मेरी समस्या यह है कि, जब मैं परिदृश्य में जाता हूं, तो मैं वेबपृष्ठ को रीफ्रेश करना चाहता हूं। चूंकि मैं जावास्क्रिप्ट में एक नौसिखिया हूं, मुझे नहीं पता कि यह कैसे करें। कृपया मेरी मददकैसे करें जब उपयोगकर्ता मोबाइल पर परिदृश्य में बदलता है तो वेब पेज रीफ्रेश करें

+2

इस और एक जवाब की तरह एक सवाल ही नहीं मौजूद है;) http://stackoverflow.com/questions/850472/how-do-i-detect-when-the- iphone-go-in-landscape-mode-via-javascript-is-ther – matzino

+0

@ManseUK धन्यवाद यू – FreshBits

+0

डुप्लिकेट से बचने के लिए कृपया इस प्रश्न को बंद करें – Murtaza

उत्तर

5

आप orientationchange jQuery मोबाइल घटना इस्तेमाल कर सकते हैं और फिर एक

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>"); 
} 

}); 
+0

मैंने आपका उपयोग किया इस तरह का कोड, अभी भी काम नहीं करता है "" – FreshBits

+0

@yuzi मैंने अपना कोड अपडेट किया है, लेकिन मेरा सुझाव है कि आप एक नज़र डालें I n jquery और jquery mobile (जो यह उदाहरण उपयोग कर रहा है) – Johan

+1

अंततः मुझे यह पसंद आया, तो यह "window.onorientationchange = function() { var ओरिएंटेशन = window.orientation; स्विच (अभिविन्यास) { केस 0: window.location.reload(); ब्रेक; केस 90: window.location.reload(); ब्रेक; केस -90: window.location.reload(); ब्रेक; } } " धन्यवाद जोहान – FreshBits

0

आपके पास टाइमर इस्तेमाल कर सकते हैं और समय-समय पर:

if (window.innerHeight > window.innerWidth) { 
    // Redirect code, window.location... 
} 
+2

यदि ऊंचाई> चौड़ाई, मोबाइल पोर्ट्रेट मोड में होगा, परिदृश्य नहीं – Johan

संबंधित मुद्दे