html5-history

Restoring content when clicking back button with History.js

与世无争的帅哥 提交于 2019-12-02 19:29:33
I've implemented History.js on a local test application. Everything seems to work, however if I press the back button in the browser, the previous content does not get restored. Do I actually have to load the content manually again (i.e. make another ajax call) when user presses the back button? Then how does github do it? I see they don't make another ajax call when clicking back button in the code tree. Here is my code: History.Adapter.bind(window,'statechange',function() { var State = History.getState(); History.log(State.data, State.title, State.url); }); $('a').each(function(index, link)

Change URL without refresh the page [duplicate]

▼魔方 西西 提交于 2019-12-02 15:24:10
This question already has an answer here: How do I modify the URL without reloading the page? 18 answers I would like to replace an url without page refresh. I need to change: https://example.com/en/step1 to https://example.com/en/step2 How to do that ? Update Based on Manipulating the browser history , passing the empty string as second parameter of pushState method ( aka title ) should be safe against future changes to the method, so it's better to use pushState like this: history.pushState(null, '', '/en/step2'); You can read more about that in mentioned article Original Answer Use history

How to set “default” value for history.pushState and replaceState?

风流意气都作罢 提交于 2019-12-02 11:01:15
问题 For browsers that use the title param, what value should we use to tell the browser to use its default? In Safari 5.1.7 (7534.57.2) , if I put null or undefined as the title param, it uses the browser default: However, Opera 12.16 uses the string "null" and "undefined" respectively: What's supposed to be the "correct" behavior? On Opera, how can we set to "default" if "null" and "undefined" doesn't work? (MDN's History docs doesn't seem to have much info regarding the allowed values for

replaceState(): a history state with url … cannot be created in a document with origin

瘦欲@ 提交于 2019-12-01 15:50:26
I have window.history.replaceState(null, null, 'about'); in main.js which are located in required/javascripts on my server. Then on the about page (located in / (root) on my server), I have a link that uses window.history.replaceState(null, null, 'about:me'); on this page. Everything works fine, but when I click on another link with the same function but with about:girlfriend as URL, I'm getting this error message: Uncaught SecurityError: Failed to execute 'pushState' on 'History': A history state object with URL 'about:girlfriend' cannot be created in a document with origin 'http://my.domain

replaceState(): a history state with url … cannot be created in a document with origin

落花浮王杯 提交于 2019-12-01 15:39:13
问题 I have window.history.replaceState(null, null, 'about'); in main.js which are located in required/javascripts on my server. Then on the about page (located in / (root) on my server), I have a link that uses window.history.replaceState(null, null, 'about:me'); on this page. Everything works fine, but when I click on another link with the same function but with about:girlfriend as URL, I'm getting this error message: Uncaught SecurityError: Failed to execute 'pushState' on 'History': A history

Is there a way to tell what direction the state is going with history.js?

允我心安 提交于 2019-12-01 01:08:18
问题 Like the title says, I'd like to be able to perform a different onstatechange event if the pushState function is called, instead of the back function. Or, if the go function is negative or positive. Example: if History.pushState() or History.go(1) are called, i want the statechange event's callback to be forwardPushState if History.back() or History.go(-1) are called, i want the statechange event's callback to be backwardsPushState 回答1: A state is some data related to a page (as the user see

Is there a callback for History.pushstate?

人走茶凉 提交于 2019-11-30 23:05:44
问题 My Google-fu pulls up nothing. When you do this: var stateObj = { state: "some state" }; history.pushState(stateObj, "page 2", "other.htm"); Is there an associated window callback? I know that there's this: window.onpopstate = function() { } Which works great for listening to when a user hits the back button. However, I want to listen to any time the URL changes at all, and I'm not sure how to do it. Is there a global callback for anytime the URL changes? 回答1: No, there's not a onpushstate or

HTML5 History API: JSON displayed when going “back” to another page, and then “forward” again

a 夏天 提交于 2019-11-30 14:00:07
问题 I have a page where there are several search / filter button which, when clicked, refresh the contents of a list below through AJAX. In the process, I'm modifying history (through pushstate) so that the new filtered page is bookmarkable, and so the back button works. I'm also listening for the popstate event, to react to Back. My code looks more or less like this: window.addEventListener("popstate", function(ev) { if (!window.history_ready) { return; } // Avoid the one time it runs on load

How to unit test a react event handler that contains history.push using Jest and Enzyme?

十年热恋 提交于 2019-11-30 12:41:55
Given a simple component: export default class SearchForm extends Component { constructor(props) { super(props) this.state = { query: '' } } onSubmit = (event) => { event.preventDefault() history.push(`/results/${this.state.query}`, { query: this.state.query }) } render() { return ( <form onSubmit={this.onSubmit}> <input type="text" value={this.state.query} onChange={event => this.setState({ query: event.target.value })} /> <button>Search</button> </form> ) } } And the test: describe('SearchForm Component', () => { it('should navigate to results/query when submitted', () => { const wrapper =

Android webview “location.replace” doesn't work

冷暖自知 提交于 2019-11-30 10:34:45
I have an Android webview with a page that redirects to another page, using location.replace(url) . Lets say that I have page "A" that redirects to page "B" (using location.replace). When pressing "back" button from page "B", the page returns to page "A", which redirects it to page "B" again. When I debug the history api (history.length), I can clearly see that on page "B" the length has incremented in "1" (only on Android 4.X webview. On iOS / web browser / Android 2.X it remains the same), which is a bug! (location.replace shouldn't change history.lenght!) Daniel I work with Yaniv on this