English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

دليل تعليمات JavaScript الأساسية

كائنات JavaScript

وظائف JavaScript

JS HTML DOM

JS متصفح BOM

دليل تعليمات AJAX الأساسية

دليل مرجع JavaScript

JS Window History

يحتوي كائن window.history على سجل التاريخ للمتصفح.

كائن history

window.historyيحتوي الكائن على قائمة بجميع الصفحات التي تم زيارتها في سجل الجلسة الحالية للمتصفح، في الإطار أو النافذة الحالية.

window.historyيمكن كتابة الكائن بدون مقدم النافذة.

بعض الأمثلة:

في القسم التالي، سيتم عرض كيفية الحصول على معلومات سجل التصفح للمستخدم.

لكن، من أجل حماية خصوصية المستخدم، هناك بعض القيود على كيفية الوصول إلى هذا الكائن من قبل JavaScript.

الحصول على عدد الصفحات التي تم زيارتها

Thehistory.lengthيعود الخاصية عدد الصفحات في سجل التاريخ الحالي للنافذة الحالية.

ويشمل ذلك الصفحة التي يتم تحميلها حاليًا.

var result = history.length; // يعود حجم سجل التاريخ الحالي للجلسة.
Test to see‹/›

يمكنك استخدام هذا الخاصية لمعرفة عدد الصفحات التي زارها المستخدم في جلسة المتصفح الحالية.

Go back to the previous page

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:

Go to the next page

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):

Go to a specific page

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.