通过JavaScript操作浏览器前进后退列表

最近经常需要解决一下前进后退的问题,在追溯webkit源代码中发现了history这个JS对象有些特殊处理是我们之前没发现的。
 
这里简述一下这两个函数的作用:
pushState为给前进后退加一个item,但不会触发网页加载。
replaceState()  则为可以替换当前的url item,也不会触发网页加载。
 
上述两者都只会在发生前进后退的时候产生影响。(当然,JS是不能跨域的)
 
对于Webkit浏览器,我们要处理以下回调,从而响应URL的变更:
//WebFrameLoadDelegatePrivate
- (void)webView:(WebView *)webView didPushStateWithinPageForFrame:(WebFrame *)frame;
- (void)webView:(WebView *)webView didReplaceStateWithinPageForFrame:(WebFrame *)frame;
- (void)webView:(WebView *)webView didPopStateWithinPageForFrame:(WebFrame *)frame;
- (void)webView:(WebView *)webView didRemoveFrameFromHierarchy:(WebFrame *)frame;
 
 
举个例子:
打开www.uc.cn后,在console输入 history.replaceState("","","http://www.uc.cn/iphone-hahah") 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章