My app is running fine on chrome but in Firefox (v 32.0) , it's creating one problem.
As after log out, if go back by clicking the browser's back button. It should not allow to go back and load the previously visited page.
I have coded well to achieve this and works fine everywhere. It works fine in chrome also. But in case of firefox browser's back button, it's not refreshing/reloading the page and simply shows the previously visited page.
I think If I make it reload the page on back button clicking then it'll be solved.
For this, I tried by the following code on that page:
<input type="hidden" id="refreshed" value="no">
<script type="text/javascript">
onload=function(){
console.log("method called.......");
var e=document.getElementById("refreshed");
if(e.value=="no")
{
e.value="yes";
}
else
{
e.value="no";
location.reload();
}
}
</script>
But it didn't work.
Any suggestion please ?
I doubt that your code works, I cannot see how it will ever reach the else because onload happens only once at page load, and reload will call it again on the next page load. To prevent the back button, you can use window.onbeforeunload.
More details here : how to stop browser back button using javascript
Related
I made a simple refresh button that used to work, and when I say 'refresh' i mean refresh to the current page (clearing data) and not a 'backspace' button that goes to the previous page.
onClick="window.location.reload()"
history.go(0)
window.location.href=window.location.href
I usually use one of these to refresh my search function to clear the data for a new search, just by refreshing the page, but all of a sudden I am getting a previous page instead. I am not sure why. I was testing on chrome. The problem is the way it is now the previous page could be anything, including something offmy site like google search ect.
Has anyone any idea what i am doing wrong?
I also tried
window.location.reload(true)
and
window.location.reload(false)
but I seem to be going around in circles.
<button onclick="window.location.reload(true);">Click me</button>
The "window.location.reload();" is javascript, to check if an error is occuring when you run this page press f12 to view your browser tools and move to the console then attempt to reload your page, any javascript error will appear there.
I have
$(document).ready(function(){alert('Page-A');});
in page A.
It works perectly fine, except when I go to some page B and come back to page A using
window.history.back();
Why does this happen and how do I fix this?
I forgot to mention, this problem occurs only in mobilephone browsers.
In your previous page (the page which is shown when you do a browser back or history.back()), add the following javascript line of code in the <script> tag in <head> section of the page:
window.onbeforeunload=function(e){};
When you attach the onbeforeunload handler, then when you visit the same page via browsers history navigation, the scripts on the page still execute.
Try with window.history.go(-1);
I let visitors click on an image to print the page
The site includes jQuery 1.6.3
In my script I've written the following:
$(window).load(function() {
$('#printButton').click(function(e) {
print();
return false;
});
});
Where 'printButton' is appears in my html as
<img src="#"
id="printButton"
... />
The print dialog opens when the user clicks on the 'printButton.' So far so good.
But my back button no longer works in chrome. The browser doesn't go back to the
previous page until I close the print dialog. I just get the little grey spinner on the tab.
This doesn't happen if I just click CTRL-P. I can go back to the previous page even when
the print dialog is still open.
I've tried this on Chrome Version 32.0.1700.107
Any ideas on how to fix my back button?
Congratulations, it appears like you've found a bug in Google Chrome. In that case there isn't much you can do about it, other than report or forget it.
I want to prevent users from reloading the page each time to get updated dynamic content. So I have used this code:
window.onbeforeunload = function() {
return "Dont need to reload the whole page. Just reload the section";
}
It's working fine except when an user closes the browser's tab/window, the same message is showing also. But I want to show the message only for reloading/F5 button, not for closing the browser's tab/window. What event handler should I have to used for that purpose?
You can physically disable the f5 button, to get functionality similar to what you want:
Disable F5 and browser refresh using javascript
Hi I have the following code:
function redirect(){
window.location.href='logged_out_chat.php';
}
...in my header and the following body tag:
<body onunload="javascript:redirect();">
...when i try this on one laptop, it redirects as it is supposed to (when you click on any link), but on my other laptop, desktop and notebook it ignores the redirect and goes to any link you click on.
I have spent hours on this...all have the same browser. I was wondering if there is an alternative way i could redirect the user when they click on a link etc.
What do you expect would happen?
When I close your page in my browser you get to redirect me to a page of your liking?
This goes againts security and user control. You shouldn't be able to interfere with the page when I close it.
The morale is don't rely on onunload to do anything non-trivial.
When a window unloads it stops processing everything, that means ajax requests, pending downloads etc, most even freeze animated gifs. Some browsers support onbeforeunload, but I completely agree with #Raynos you can't count on the event, so using it is not a good design decision.
You can't hijack onunload and redirect the user. That would prevent the user from closing their browser, refreshing the page, or manually navigating to another site. If that's what you are trying to do, you are out of luck. All onunload is good for is asking the user if they are sure they want to leave the page.
If, however, you are trying to cause a clicked link to go to a different location, that's easy. To change the link permanently:
myLink.href = 'logged_out_chat.php';
If you want to change the links temporarily, add a click handler that you can later remove:
function goToLoggedOutChat(e)
{
e.preventDefault && e.preventDefault();
e.returnValue = false;
location.href = 'logged_out_chat.php';
}
mylink.onclick = goToLoggedOutChat;
To re-enable the link:
mylink.onclick = null;
To do it for every link on the page:
for (var i=0; i<document.links.length; i++)
{
document.links[i].onclick = goToLoggedOutChat;
}