Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add history api example #236

Merged
merged 11 commits into from
Nov 17, 2023
Merged

Conversation

wbamberg
Copy link
Contributor

@teoli2003 , the point of this is to replace https://developer.mozilla.org/en-US/docs/Web/API/History_API/Example, which I don't think is viable as an example.

I've used https://github.com/lesjames/history-api-demo, which in turn is based on http://html5doctor.com/history-api/, as a starting point, but have pretty much completely rewritten it.

The general idea is to show how to use the history API to allow back/forward navigation to work when you're doing a single-page app thing using fetch().

However I don't really know what I'm doing here so I'm very open to feedback!

Copy link
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was really good.

  • I propose to add a few comments, explaining the part that are related to the History API
  • I've updated document.title in displayContent() so that the history in the navigator looks better.

});

// Handle forward/back buttons
window.addEventListener("popstate", (event) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! This is one case where window is needed! It is the object window (and not the global scope) we are using.

Nice!

history-api/script.js Show resolved Hide resolved
history-api/script.js Show resolved Hide resolved
history-api/script.js Outdated Show resolved Hide resolved
history-api/script.js Show resolved Hide resolved
history-api/script.js Show resolved Hide resolved
@wbamberg wbamberg requested a review from teoli2003 November 17, 2023 16:19
Copy link
Contributor

@teoli2003 teoli2003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants