I am using Google chrome and i have tested, using one of the detection techniques mentioned in Dive into HMTL 5, for support for the History API. But the following piece of code does not seem to work. Can anybody let me know what am i missing out ?
function demo()
{
alert("history changing");
if(window.history && history.pushState)
{
alert("api supported");
}
else
alert("api not supported");
for(i=0;i<20;i++)
{
history.pushState(null,null,"\try.html");
}
}
The for loop, wherein i expect the url "try.html" to be inserted 20 times in the history of the browser, does not seem to work. I called this function from a page, named "try.html", wherein the function "demo" is executed on page load. The page, "try.html", simply has a line of normal text. What i want to do is that when the user, after loading the page, "try.html", clicks on the back button of the browser he'll still remain on the same page, since the history should be containing 20 entries of the same page, i.e. "try.html" but it does not. Why?
It works for me. There are two problems you could be having:
file://
URI then you'll get a security error. Chrome is silent about this but Firefox reports the error. You need to put the page on a web server and access it over http://
."\try.html"
means a tab character followed by ry.html
, you probably mean "/try.html"
.Here is a working example based on your code.