JavaScript history Object In Hindi

📔 : Java Script 🔗

history object , user द्वारा visit किये गए सभी URLs को contain करता है। इसके कई useful methods और properties होती हैं, जिनकी help से हम  आसानी से visit किये गए URLs पर navigate कर सकते हैं।

JS Properties and Methods of history object

  • length
  • back()
  • forward()
  • go()

JS history length

length property हमें visit किये URLs की length return करता है। visit किये गए page के according length property की value change होती रहती है।

Example

Copy
<script type="text/javascript">
console.log(`history : ${window.history.length}`); /* we can access it , both type*/
console.log(`history : ${history.length}`);
</script>

चूंकि history , window object का ही child object है इसलिए history Object की सभी properties और methods को with window और without window के भी access कर सकते हैं।

JS history back

history.back()  method का use , previous visited page पर से फिर जाने के लिए किया जाता है।

Example

history.back();

Important
Note that ,अगर URL history stack में previous page URL नहीं है , तो history.back() method work नहीं करेगा ।
For example just click on the Back button .


JS history forward

 history.back() की तरह forward() का use next page visit करने के लिए किया जाता है।

window.history.forward();

?forward() move करने के लिए history stack में next Page का URL होना चाहिए।

For Example : click on this Next button

JS history go

back() और forward() का use , previous और next URL visit करने के लिए किया जाता है , But history.go() method का use करके हम किसी particular URL को visit कर सकते हैं।


इसमें एक integer number pass किया जाता है , previous URLs को visit करने के लिए negative integer और forward / Next move करने के लिए positive integer pass करते हैं।

Syntax
window.history.go(-1) /* for previous page */
window.history.go(1) /* for next page */

और अगर history.go() method में 0 या कुछ pass नहीं करते , तो current page Refresh हो जाता है।

Example
<kbd onclick="window.history.go();">Refresh</kbd>

इस button पर click करने पर current page refresh हो जायेगा। Refresh

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers