Using JS window.print() breaks back button in chrome - javascript

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.

Related

Window.open and window.print blocking JavaScript

I have a site where a particular page has two buttons that open pages in new tabs. One page is a preview of an item, and one is the print of that item.
// Preview button's click event
window.open('my.preview.url.com', 'preview');
// Print button's click event
window.open('my.print.url.com, 'print');
On the print page, window.print(); is call on page load.
This seems to create a bit of an issue on some browsers. Opening the print page and not closing the print preview results in all of the JavaScript being blocked on the originating page (with the buttons) and the preview page (if one had been opened previously).
This appears to not happen in all browsers. For example, Chrome displays the issue but Firefox does not.
This is similar to a similar unanswered post, which has a useful fiddle at http://jsfiddle.net/Zicane/7ntsb7hh/10/
Hoping someone might know the solution to both issues.

Refresh button now not working

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.

firefox browser back button doesn't refresh the page

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

Can I Load Window After Click?

I have a custom Modal Box (just like the browser's alert())
Usually, using alert() the browser pauses that underneath page rendering and executions,
how to get the same behavior of restricting the rest of the window to load unless one confirms OK in the Modal element?
So how to
Pause window load -> Show modal -> (OK) -> continue window load
New Edit
Instead of stopping page load, why not remove all of the page show popup, then place the document back ie using JQuery...
var pageBody = $('body').html(); //Copies Body of Page
pageBody = $('body').html(""); //Delete the Body
/* Do Some Awesome Code here*/
$('body').html(pageBody); //Place Body Back
This will allow page to load, remove it, execute code then place it back. The other method below will not work as stopping the page, will stop EVERYTHING including any other code you are running.
Old Answer
You could use
window.stop(); //works in all browsers but IE
if ($.browser.msie) {document.execCommand("Stop");}; //works in IE,
document.execCommand works in IE, however it does stop some of FF, NS and some other browsers' functions. Like displaying GIF's animation for example. Using "if browser is IE" makes these two codes work perfectly in all browsers.
This code will simply pause the execution of the page. Like clicking the STOP button on your page but you will need to reload to start the page again..
I would personally advise simply placing a fullscreen white div behind your popup box but above your popup to give the idea of the popup is only there while the user will be none the wiser that the rest of the page has stopped loading

How to show back and forward button on popup opened thru window.open or self.open for Chrome?

i am opening the popup window with below code snippet
self.open('myJSPPage','ServicePopUp','height=600,width=800,resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes');
Once the window opens i do not see any back button or forward button on popup. I just see title then address bar under it and then myJSPPage under address bar.
I am not getting how to show back and forward button on popup?
Edit:- i am using google crome. Looks like above code working on IE
i tested this example and it gives me forward and back button on FF
try this
<!-- Codes by Quackit.com -->
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
Open a popup window
jsfiddle live demo for your code an mine it gave me buttons on FF test
update:
yes you are right chrome does not give the result expected
possible duplicate
another asked question in stack over flow
Unfortunately Chrome only supports a small set of window features when using window.open. If you believe that this is a bug or an issue you can file it at http://crbug.com.
If you just use window.open(url) then it will open a new tab in the same window with the buttons you desire.
jsfiddle demo

Categories

Resources