English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
يحتوي كائن window.history على سجل التاريخ للمتصفح.
window.historyيحتوي الكائن على قائمة بجميع الصفحات التي تم زيارتها في سجل الجلسة الحالية للمتصفح، في الإطار أو النافذة الحالية.
window.historyيمكن كتابة الكائن بدون مقدم النافذة.
بعض الأمثلة:
في القسم التالي، سيتم عرض كيفية الحصول على معلومات سجل التصفح للمستخدم.
لكن، من أجل حماية خصوصية المستخدم، هناك بعض القيود على كيفية الوصول إلى هذا الكائن من قبل JavaScript.
Thehistory.lengthيعود الخاصية عدد الصفحات في سجل التاريخ الحالي للنافذة الحالية.
ويشمل ذلك الصفحة التي يتم تحميلها حاليًا.
var result = history.length; // يعود حجم سجل التاريخ الحالي للجلسة.Test to see‹/›
يمكنك استخدام هذا الخاصية لمعرفة عدد الصفحات التي زارها المستخدم في جلسة المتصفح الحالية.
Thehistory.back()The method will load the previous URL in the history list.
This is the same as clicking the 'Back' button in the browser.
<button onclick="history.back();">Go Back</button>Test to see‹/›
The following output will be displayed by the above code:
Thehistory.forward()The method will load the next URL in the history list.
This is the same as clicking the 'Forward' button in the browser.
<button onclick="history.forward();">Forward</button>Test to see‹/›
The following output will be displayed by the above code (this example will not work if the next page does not exist in the history list):
You can also usehistory.go()The method loads a specific page from the session history.
This method takes an integer as a parameter.
Negative integers move backward in the history, and positive integers move backward in the history.
<button onclick="history.go(-2);">Go Back 2 Pages</button>Test to see‹/›
The following output will be displayed by the above code:
Note:If you try to access a page that does not exist in the Windows history, then this methodhistory.back(),history.forward()andhistory.go()There will be no action.