<script>
function sync_data() {
localStorage.setItem("syncDataClicked", true);
location.reload();
}
window.onload = function () {
if (localStorage.getItem("syncDataClicked") === "true") {
localStorage.removeItem("syncDataClicked");
sync_data('show');
}
};
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body>
<input type="submit" name="submit3" onclick="sync_data()" value="Sync data">
</body>
</html>
Html:
<input type="submit" name="submit3" onclick="sync_data()" value="Sync data">
JS:
function sync_data() {
window.onload = function () {
setTimeout(function () {
sync_data('show');
}, 5000);
}
}
This js is not working. After onclick and page reload I need to add the pop by function sync_data(). Is there any solution. I have updated with local storage but its showing the popup message
2
Answers
Your window.onload function is already inside the sync_data function. So window.onload will not be triggered because the page is already loaded when the button is clicked. So your window.onload function should excute before excute the sync_data function. So inside the sync_data function you should include flag. According to that flag window.onload function will triggered. you can use localStorage to store a flag. This is my suggest code. I am not sure is it work or not. I was add custom pop up alert to code.
You may use the following code:
Hope you find this helpful!