software mastery, the fun way

See the Trailer: Head First HTML5 Programming

See the Trailer: Head First HTML5 Programming

HTML has been on a wild ride. Sure, HTML started as a mere markup language, but more recently HTML’s put on some major muscle. Now we’ve got a language tuned for building web applications with Web storage, 2D drawing, offline support, sockets and threads, and more. And to speak this language you’ve got to go beyond HTML5 markup and into the world of the DOM, events, and JavaScript APIs.

Now you probably already know all about HTML markup (otherwise known as structure) and you know all aboutCSS style (presentation), but what you’ve been missing is JavaScript (behavior). If all you know about are structure and presentation, you can create some great looking pages, but they’re still just pages. When you add behavior with JavaScript, you can create an interactive experience; even better, you can create full blown web applications.
Head First HTML5 Programming is your ultimate tour guide to creating web applications with HTML5 and JavaScript, and we give you everything you need to know to build them, including: how to add interactivity to your pages, how to communicate with the world of Web services, and how to use the great new APIs being developed for HTML5.

 

  • http://www.facebook.com/profile.php?id=100000290619604 XCloud Strifex

    I am one of people purchased your book HTML5 and some code didn’t work on all latest browser. I don’t know where am I seek for help or contact you about this one so I posted it here as a comment. I tried your codes in geolocation chapter and JSON Chapter. Why is that it is not working? I use Firefox 8, Safari 3.2.3, Google Chrome 15.0.874.121 m, and Internet Explorer 9.

    Geolocation works in IE 9 but not on my other browser.

    Mighty Gumballs codes sometimes didn’t work on some browser. It works sometimes in Google Chrome and Firefox 8 sometimes not.

    Why is that so? Please help me with this one.

  • Anonymous

    Hi,
    The most recent versions of Firefox and Safari (for the Mac, anyway) are Firefox 6 and Safari 5. So make sure to do an update again just to be sure. (The versions may be different on Windows, I’m not sure).

    For those particular examples, it’s also important that you serve your files using a local server rather than from file://. Some browsers have security restrictions around geolocation and Ajax/JSON requests for file:// which makes these examples not work if you’re not using http://.

    Take a look at the JavaScript console to see if you find any errors.

    Did you download the code or are you typing it in? I’ve tested the code on the most recent versions of all the browsers and it worked for me… If you can’t get it working, please contact me with more specific details about the problems.

    Hope this helps…

    Cheers! Elisabeth

  • http://twitter.com/stevenmarx Steven Marx

    I’m on page 153 of the book, “Test drive your constructor …”, and finding the Ready Bake code for getting the time no longer works with the new code and can’t figure out why. The error I get is TypeError: ‘undefined’ is not an object (evaluating ‘str.match’) and the line number. Here is that line of code:

    var time = str.match(/(d+)(?::(dd))?s*(p?)/);

    And here is the whole block of code, copied from your example, which worked in earlier iterations of the movie project from this chapter, but doesn’t seem to anymore:

    function getTimeFromString(str) {
    var theTime = new Date();
    var time = str.match(/(d+)(?::(dd))?s*(p?)/);
    theTime.setHours( parseInt(time[1]) + (time[3] ? 12 : 0) );
    theTime.setMinutes( parseInt(time[2]) || 0 );
    return theTime.getTime();
    }

    And just to be safe, I supposed, here’s the whole script as I have it:

    function Movie(title, genre, rating, showtimes) {
    this.title = title;
    this.genre = genre;
    this.rating = rating;
    this.showtimes = showtimes;
    this.getNextShowing = function() {
    var now = new Date().getTime();
    for (var i = 0; i 0) {
    return “Next showing of ” + this.title + ” is ” + this.showtimes[i];
    }
    }
    };
    }

    var banzaiMovie = new Movie(“Buckaroo Banzai”, “Cult Classic”, 5, ["1:00pm", "5:00pm", "7:00pm", "11:00pm"]);
    alert(banzaiMovie.getNextShowing());
    var plan9Movie = new Movie(“Plan 9 from Outer Space”, “Cult Classic”, 2, ["3:00pm", "7:00pm", "11:00pm"]);
    alert(plan9Movie.getNextShowing());
    var forbiddenPlanetMovie = new Movie(“Forbidden Planet”, “Classic Sci-fi”, 5, ["5:00pm", "10:00pm"]);
    alert(forbiddenPlanetMovie.getNextShowing());

    function getTimeFromString(str) {
    var theTime = new Date();
    var time = str.match(/(d+)(?::(dd))?s*(p?)/);
    theTime.setHours( parseInt(time[1]) + (time[3] ? 12 : 0) );
    theTime.setMinutes( parseInt(time[2]) || 0 );
    return theTime.getTime();
    }

    Any help greatly appreciated as I’m stuck on this.

    Steve

  • Elisabeth Robson

    Hi Steve,
    I typed in what you have above, and had a couple of problems in the Movie object, possibly due to the comment system messing up the code a bit.

    Anyway, it looks like the problem is you’re passing the length of the showtimes array instead of the item to the function getTimeFromString. You’re passing this.showtimes.length[i] instead of this.showtimes[i]. If you look at page 152, make sure your code matches exactly!

    Elisabeth

  • http://twitter.com/stevenmarx Steven Marx

    Thanks loads, that was it. I had even been messing with that at some point as I thought the problem seemed to be there, obviously didn’t catch it just right. That’s the problem I have with the programming, the little mistakes and I go back over trying to make sure it’s exact but my brain shows me what I want to see. :) Thanks again, I really appreciate the quick response.

  • http://mercvision.blogspot.com/ Harshal Bhave

    I could not run the samples in Geolocation API. Do they work only if it is deployed on server? Somehow some of the examples hosted by your website were not working on FireFox as well.

    Any idea ?

  • Anonymous

    You should try running these from a local server,yes. Which version of Firefox are you using?