Document.Onload doesn't work properly in Kik

121 views Asked by At

I was recently trying my best to create a Kik app that dynamically loaded some content -- messages -- into a textbox when the app launched. document.onload wasn't doing it for me. I tried JQuery's $(document).ready and $(window).load to no avail.

Simple code snippets like this were failing, and I couldn't understand why. They would refuse to function until I attempted to interact with another UI element, resized the screen by rotating my phone, etc...

$(document).ready(function() {
    kik.getUser(function(user) {
        $('#myDiv').html(user.username);
    });
}

This was pretty infuriating... why could I not get Kik to do both in-getUser functions and regular onLoad ones?

1

There are 1 answers

0
AudioBubble On

Don't ask me why, but this works. I'm just going to assume that you CANNOT wrap kik.getUser in a $(document).ready statement!

But who cares -- if kik.getUser works, then you already have access to the DOM. Cheers!

// Kik user-specific JS
if(kik.utils.platform.browser.kik) {
        kik.getUser(function (user) { if ( user ) {
            $('#message').html("I work now.");
        }});
});

// Kik-agnostic JS
$(document).ready(function() {
    $('#version').html("I work now too.");

});