Tag Archives: how to

Smartphones and tablets are devices that are frequently used to browse websites. JavaScript now has a couple of events for hand held devices. For this tutorial, you’ll need to have a mobile phone. I’ll be using the Iphone for this tutorial. Feel free to skip this tutorial if you don’t have a device handy. Orientation The orientationchange event fires when …

It’s time to take a look at keyboard events. Another popular feature of JavaScript is the capability to detect which keys were pressed and how they were pressed. Let’s first update our document to this. [crayon-5ce9593cd001f449481747/] Sweet! Now, let’s clear up the script and add this bit of code. [crayon-5ce9593cd002f077407497/] The first kind of event is the keydown event. This …

Keep track of how the mouse interacts with the web page. It is the primary device for navigation after all. Whenever mouse events occur, you’re passed in a lot of information as to where the mouse is located or what is also happening with the mouse. Let’s take a look at how this works. Coordinates We’re going to keep our …

UI events are events that aren’t specific to the document, but the window object. These events fire when something happens to the browser or window. Loading Events Loading events fire when the window has loaded all scripts, images, files and styles. There are also unloading events for when the user leaves the page. Update your document to this. [crayon-5ce9593cd0f08508604980/] Let’s …

The event object is passed into your function whenever an event occurs. This object contains information about the event and even allows you to change how the event phases flow. We’ll be working with our previous example. Update your script to this. [crayon-5ce9593cd15a0058675188/] Our functions have been updated so that we can reference the event object. The event parameter will …

If you’ve seen my events tutorial in my JavaScript basics tutorial series, then you already know how to use events. There’s another way of using events with event handlers. Before we begin, let’s update the <body> tags in our document to this. [crayon-5ce9593cd1d4b655556742/] We just have a simple button in our document with the ID btn. To add an event, …

HTML5 is fairly new and it’s slowly being adopted by all web browsers today. A special feature of HTML5 is the ability to define custom data attributes. A data attribute is your own attribute that can contain information about an element. Let’s update our document to this. [crayon-5ce9593cd25f1985179437/] To create a data attribute, you simply create an attribute with the …

The selectors API is a simpler way to grab elements by using CSS queries. If you recall, you can change the styles of an element using CSS. Here’s an example of how you would do so. [crayon-5ce9593cd2b6d659662534/] To grab an element in general, you just type in the tag name. To grab an element with an ID, you type a …

The navigator object allows you to grab information about the browser and visitor’s computer. You can grab the browser name, plugins, OS, language, etc. Properties Clear your script and add this bit of code. [crayon-5ce9593cd3259561758587/] The navigator object is pretty tricky. Even though the navigator object has been around since Netscape Navigator 2, the properties and methods are supported in …

The location object contains information about the current URL you’re visiting. It can give you helpful information such as the port number, whether or not the site is using SSL and even allows you to redirect the user. Properties Clear your script and add this bit of code. [crayon-5ce9593cd37b5427236713/] There are a couple of properties of the location object, but …