![]() ![]() It works like when you click the Forward button. Similarly, you can move forward by using the forward() method: history. This behaves like you click the Back button in the toolbar of the web browser. To move backward through history, you use the back() method: window. The history object provides three methods for navigating between pages in the history stack: However, you can use the history object to navigate back and forth without knowing the exact URL. ![]() To manipulate the history stack, you use the history object which is a property of the window object: window.history Code language: JavaScript ( javascript )įor the security reason, it’s not possible to query the pages that a user have visited. The history stack stores the current page and previous pages that you visited. If you navigate to another webpage, the web browser also creates a new entry in the history stack. When you launch the web browser and open a new webpage, the web browser creates a new entry in its history stack. Introduction to the JavaScript history object. Here we discuss the introduction to JavaScript History Object along with respective examples.Summary: in this tutorial, you will learn how to access the browser’s session history by using the JavaScript history object. This is a guide to JavaScript History Object. This history object can be used to go to a particular page or URL, previous URL or forward URL in the visited URLs using three methods which are go(), back() and forward() respectively. The browsers history object contains history of all the web pages or URLs the user has been visited. Output: And once we click the above Forward Method button, the output is Output: once we click the above Back Method button, the output is Here again have two html pages h1.html and h2.html, where h1.html contain the link for h2.html and history object forward() method, the h2.html contain same as above. The history.forward() method used to load the forward page from history URLs. Next we rewrite the above html code to see working of history.forward() method. Click the below button to go back prevous page visited by the user by using go method. Here we will create again two html pages h1.html and h2.html, where h1.html will contain the link for h2.html and h2.html will contain code to call history object go(-1) method which go just one step backward. If we pass greater than 0 value to the go() method then it loads the forward page for example go(2) goes two steps in forward direction, if we pass lesser than 0 value to the go() method then it loads the backward page for example go(-1) goes one step in backward direction. Next we write the html code to understand the working of history.go(), the history.go() method used to loads the particular page(forward or the backward) from history URLs. Output: And once we click the above Back Method button, the output is Output: Once we click the above link, the output is Click the below button to go back prevous page or URLs visited by the user. So once the back method called it go to the previous URL that is h1.html, as in below code – Here we will create two html pages h1.html and h2.html, where h1.html will contain the link for h2.html and h2.html will contain code to call history object back() method. Next we write the html code to understand the working of history.back() method more clearly with the following example, the history.back() method used to load the previous page from history URLs. Output: Once we click on the Length Property button the output is Īlert( "The number of URLs in the browser history is " + ) Click the below button to see the number of URLs visited by the user. This Is An Example For History Object In JavaScript Next we write the html code to understand the working of history.back() method more clearly with the following example, the history.back() method used to load the previous page from history URLs using the button element:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |