Introduction
The window.history object represents the user's history list of viewed web pages. The history object is an array that holds a history of the pages that have been loaded. The amount of information you can get from the history object is limited. The properties and methods of the history object are limited. Since there is no way to determine the position of the current URL in the history object.
The history.back() method loads the previous URL in the history list. It is equivalent to clicking the Back button in the browser and the second method of history is the forward() method that loads the next URL in the history list. It is equivalent to clicking the forward button in the browser.
The following example shows the browser history using a web application in TypeScript. In this example we use two functions, Back() and Forward(). In the Back() function we call history.back() method, it loads the previous URL in the history list and the Forward() function calls the history.forward() method, it loads the next URL in the history list.
Step 1
Open Visual Studio 2012 and click "File" -> "New" -> "Project...". A window is opened. In this window, click "HTML Application for TypeScript" under Visual C#.
Give the name of your application as "Window_History" and then click "Ok".
Step 2
The project will then be created. A new window is opened on the right side. This window is called the Solution Explorer. The Solution Explorer contains the ts, js, css and aspx page files.
Coding
app.ts
- class Window_History {
- Back() {
- window.history.back();
- }
- Forward() {
- window.history.forward();
- }
- }
- window.onload = () => {
- var obj = new Window_History();
- var objback = < HTMLButtonElement > document.getElementById("Back");
- objback.onclick = function() {
- obj.Back();
- }
- var objforward = < HTMLButtonElement > document.getElementById("Forward");
- objforward.onclick = function() {
- obj.Forward();
- }
- };
Window_History_Demoaspx.aspx
- <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="Window_History_Demoaspx.aspx.cs"
- Inherits="Window_History.Window_History_Demoaspx"%>
- <!DOCTYPEhtml>
- <html
- xmlns="http://www.w3.org/1999/xhtml">
- <headrunat="server">
- <title></title>
- <scriptsrc="app.js">
- </script>
- </head>
- <body>
- <formid="form1"runat="server">
- <div>
- <asp:LabelID="Label1"runat="server"Font-Bold="True"Font-Italic="True"Font-Size="Large"ForeColor="Blue"Text="Window History In TypeScript">
- </asp:Label>
- </div>
- </form>
- <p>
- <inputid="Back"type="button"value="Back"/>
- <inputid="Forward"type="button"value="Forward"/>
- </p>
- </body>
- </html>
app.js
- var Window_History = (function() {
- function Window_History() {}
- Window_History.prototype.Back = function() {
- if (!window.history.back()) {
- alert("No Any Previous URL in The History List");
- }
- };
- Window_History.prototype.Forward = function() {
- window.history.forward();
- };
- return Window_History;
- })();
- window.onload = function() {
- var obj = new Window_History();
- var objback = document.getElementById("Back");
- objback.onclick = function() {
- obj.Back();
- };
- var objforward = document.getElementById("Forward");
- objforward.onclick = function() {
- obj.Forward();
- };
- };
Referenced By
http://www.typescriptlang.org/