2013-03-24 56 views
1

我學習技術:歷史API pushState的(HTML5)pushState的:如何添加查詢字符串沒有重定向

我需要爲工作的網址重定向withput因爲我有服務器的CherryPy的命令。

我無法從Cherrypy傳輸數據(使用Mako模板轉換爲Javascript),但我想更改網址。

舊網址是

file:///media/DATA/prototypefin4/s.html 

並在URL自動添加foo=1&foo=2(變量s)與History.pushState

file:///media/DATA/prototypefin4/s.html?=foo=1&foo=2 

但如何?

我的代碼:

<!DOCTYPE HTML> 
<html> 
<head> 
<title>Example - History API pushState</title> 
</head> 
<script src="http://balupton.github.com/history.js/vendor/jquery.js"></script> 
<script src="http://balupton.github.com/history.js/scripts/bundled/html4+html5/jquery.history.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script> 
<body> 

<input id = 'button1' type = 'button' value = 'history.pushState' onclick="updateHistory()"/> 

<script type = 'text/javascript'> 

var count ="?foo=1&foo=2"; 

function updateHistory() 
{ 

History.pushState(count,null,file:///media/DATA/prototypefin4/s.html); 

} 

</script> 

</body> 
</html> 
+0

這是否可能?我可以看到它的一些問題。 – 2013-03-24 12:35:12

+1

我認爲可能的錯誤是在History.pushState(count,null,file:///media/DATA/prototypefin4/s.html); 因爲在論壇中有評論 我在沒有服務器的情況下使用我的電腦。 解決方案是什麼? – 2013-03-24 12:44:26

+0

「我在沒有服務器的情況下使用我的電腦,解決方案是什麼?」 - 安裝[Apache](http://httpd.apache.org/)。 – Quentin 2013-03-25 15:46:08

回答

2

你的腳本語法無效。根據the docs,以下參數是正確的:

History.pushState(null, "", "file:///media/DATA/prototypefin4/s.html"+count); 
相關問題