开发者

Detecting orientation change on BlackBerry 9800 via JavaScript

开发者 https://www.devze.com 2023-04-10 02:58 出处:网络
I have a bit of JavaScript (jQuery) to catch orientationchange and create a JS alert when triggered: $(\'document\').ready(function(){

I have a bit of JavaScript (jQuery) to catch orientationchange and create a JS alert when triggered:

$('document').ready(function(){

    $('body').bind('orientationchange', function(e){
        alert('orientation change triggered');
    });

});

link: http://jsbin.com/owebax/4

That works fine on an iPhone. It doesn't work on a BlackBerry 9800 running OS6.

In doing some googling, it appears that the issue might be that BlackBerry watches 'window' rather than 'body' for orientation change. I bound the event to window instead: http://jsbin.com/owebax/5

But that still doesn't work on the Blackberry (and now no longer will work on the iPhone.)

Has anyone got orientationchange JS events to fire on the BlackBerry 9开发者_运维百科800?


I wish that in addition to 'your answer' for answering your question there was a 'embarrassing user error' flag of some sorts.

So it turns out my issue was simple syntax snafu. Instead of trying to bind to window properly as such:

$(window).bind...

I was looking for a tag called 'window'

$('window').bind...

'doh!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号