My doubt is regarding history api feature of html5 which is using ajax script.
In my code after loading index.html, i have tried to open html content using link in central section of page. Upto this is done but when i click to back button then url is changing but content was of previous page.
following is my js code : - function supports_history_api()
-
{
-
return !!(window.history && history.pushState);
-
}
-
-
function page_cal(href)
-
{
-
var page_request = false;
-
if (window.XMLHttpRequest) // if Mozilla, Safari etc
-
page_request = new XMLHttpRequest();
-
else if (window.ActiveXObject) // if IE
-
{
-
try
-
{
-
page_request = new ActiveXObject("Msxml2.XMLHTTP");
-
-
}
-
catch (e)
-
{
-
try{
-
page_request = new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
catch (e){}
-
}
-
}
-
-
page_request.open("GET","../PA-20/pages/"+href.split("/").pop(),false);
-
page_request.send(null);
-
if (page_request.readyState==4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
-
{
-
document.getElementById("opencontent").innerHTML = page_request.responseText;
-
return true;
-
}
-
return false;
-
}
-
-
-
function addClicker(link)
-
{
-
//alert(link+"1st");
-
link.addEventListener("click", function(e)
-
{//alert(link+"2nd");
-
if (page_cal(link.href))
-
{
-
alert(link.href+" Clicked !");
-
//var url = link.href;
-
-
var linksElement = document.getElementById('id');
-
var pathname = link.href;
-
var stateObj = { first: "home",
-
second: "products",
-
third: "promoters",
-
fourth: "aboutus",
-
fifth: "contact",
-
};
-
-
history.pushState(pathname, null, link.href);
-
alert(history.state);
-
e.preventDefault();
-
}
-
}, true);
-
}
-
-
-
-
function setupHistoryClicks()
-
{
-
addClicker(document.getElementById("home"));
-
addClicker(document.getElementById("products"));
-
addClicker(document.getElementById("promoters"));
-
addClicker(document.getElementById("aboutus"));
-
addClicker(document.getElementById("contact"));
-
addClicker(document.getElementById("kalonji"));
-
addClicker(document.getElementById("chilli"));
-
addClicker(document.getElementById("jaiphal"));
-
addClicker(document.getElementById("jeera"));
-
addClicker(document.getElementById("elaichi"));
-
addClicker(document.getElementById("malkingini"));
-
-
}
-
-
-
-
window.onload = function(e)
-
{
-
if (!supports_history_api())
-
{return;}
-
setupHistoryClicks();
-
e.preventDefault();
-
window.setTimeout(function()
-
{
-
window.addEventListener("popstate", function(e)
-
{
-
alert( " Back button is cliecked ! " + "location: " + document.location + ", state: " + e.state);
-
-
location.reload();
-
-
page_cal(document.location);
-
-
}, false);
-
-
}, 1);
-
}
Thanks in advance !
Regards,
Swappy
1 1999 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ed |
last post by:
Hi,
I have an html page with a div element within a form for dynamically
creating textfields.
The problem is when I click a link on the page, or the submit button,
then click the back button,...
|
by: Earl Teigrob |
last post by:
This is an odd one. When I first display a thumbnail page and the user
clicks one of the image links, the user goes to the correct page. If the
user uses my application back button, (called...
|
by: pmud |
last post by:
Hi,
I have created a very simple ASP.NET application which has a couple of
ImageButtons which go to different SQL reports on clicking them. I have used
Response.Redirect to send the user to the ...
|
by: gferreri |
last post by:
Hi all,
I've stumbled on an interesting problem with the way Firefox handles
form submitting with the enter key.
I'm putting together a page that has one form element with multiple
controls...
|
by: mjahabarsadiq |
last post by:
I would like to reload the page when it is redirected by the browser's Back or Forward button.
I tried the following but it does not works.
<link rel="prev" href="url">
<link rel="next"...
|
by: manojsingh |
last post by:
hi,
I am writing a code for logout.jsp and used invalidate() method of session object. The program runs perfectly but afte logout when i click back button of window it shows the previous page...
|
by: viswammamilla |
last post by:
Hai i did one application ,its an intranet web application using asp.net and vb.net.
Once user login into the application and did some task whenever user hits back button it will come back to one...
|
by: jalpari |
last post by:
hi all,
i have created a form in which i have a button for searching records from database, when a record is found it'z displayed in the table fields and whenever the record'z not found it displays...
|
by: Jimmy White |
last post by:
Note:
I'm not trying to prevent back button! So I'm looking for solution, not a patch.
Shortly:
How to prevent going backwards to login and then refreshing the page (thus resending the username...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| | |