Wednesday, May 18, 2011

HTML in AIR: Part 7

In this tutorial we are going to learn about HTMLHistoryItem class.

HTMLLoader stores the history of already viewed page in objects of a class called HTMLHistoryItem. This class has several properties: url, originalURL, title and isPost.

The url property is basiscally the URL address of the page.

The originalUrl property is used to store the original url of the page that AIR intentionally referred to. For example, some pages sometimes have redirection scripts, that send visitors to another page as soon as the redirection script loads - the originalUrl property will store the url of the page that we have initally went to, before the redirection. If there is no redirection - then originalUrl and url properties have the same value.

The title property is - you guessed it - the title of the html page.

Finally, the isPost property is a boolean value, which is used to show if any data was sent to this page using the POST method.

The HTMLLoader page also has a property called historyLength, which stores a value that we can read to see how many history items do we have in the history journal. Each history item is an object of the HTMLHistoryItem class.

We have a method called getHistoryAt() at our disposal, and this method is used to get to a HTMLHistoryItem with a specified index. If the journal has at least one object, the getHistoryAt() method with 0 passed as the only parameter will return the oldest item in the history.

myHtml.getHistoryAt(0); // Returns the oldest item

We already know about the existence of the historyLength method. Because all history is just an array of HTMLHistoryItem objects, the final item in that list (which is the newest entry in the history journal) can be reached by historyLength - 1 index.

myHtml.getHistoryAt(myHtml.historyLength-1); // Returns the newest item

We already know about the historyBack() and historyForward() methods from the previous tutorials, which are the methods that are used to get to the previous and next pages in the history list.

There is, however, one more method that I should mention, and that is historyGo(). Basically, the idea is the same as with the historyBack() and historyForward() methods, except that here you can specify how many pages do you want to go pack.

For example, if you want to go 3 pages back, pass 3 as the parameter for the function.

myHtml.historyGo(3);

And, to go forward in the history list, use a negative value. The following code will take you 3 pages forward in your history:

myHtml.historyGo(-3);

And that's all for now!

Thanks for reading!

Related:

HTML in AIR: Part 1
HTML in AIR: Part 2
HTML in AIR: Part 3
HTML in AIR: Part 4
HTML in AIR: Part 5
HTML in AIR: Part 6
HTML in AIR: Part 8
HTML in AIR: Part 9
HTML in AIR: Part 10
HTML in AIR: Part 11
HTML in AIR: Part 12
HTML in AIR: Part 13
HTML in AIR: Part 14
HTML in AIR: Part 15
HTML in AIR: Part 16
HTML in AIR: Part 17

1 comment:

Anonymous said...

I love you man. :)

Post a Comment