Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment reload causes alert box in Firefox and Safari #142

Open
rgilman opened this issue Dec 3, 2022 · 5 comments
Open

Comment reload causes alert box in Firefox and Safari #142

rgilman opened this issue Dec 3, 2022 · 5 comments

Comments

@rgilman
Copy link
Member

rgilman commented Dec 3, 2022

Back in Oct 15 (see PR #133), we added some JS to reload comments after submitting a new comment in docs. Here's the script:

	jQuery('#submit').click(function(){
		setTimeout(function(){
			document.location.reload();
		}, 250);
	});

It all worked great in Brave/Chrome but now I'm discovering that our script causes an alert to briefly appear in Firefox. In Safari, the alert appears and needs to be dismissed by the user.

@iangilman, how can we fix this?

@rgilman rgilman changed the title Comment reload cause alert box in Firefox and Safari Comment reload causes alert box in Firefox and Safari Dec 3, 2022
@rgilman
Copy link
Member Author

rgilman commented Dec 3, 2022

The alert in firefox contains the base url for the site. The alert in safari is blank except for an OK button.

@iangilman
Copy link
Member

Funky. I don't know why this is happening.

I suppose one possibility is there's a beforeunload event handler somewhere else on the page. You could test that hypothesis by adding something like this before your reload:

window.onbeforeunload = function() {};

That should overwrite any existing handler for that event.

@rgilman
Copy link
Member Author

rgilman commented Dec 4, 2022

I tried

	jQuery('#submit').click(function(){
		window.onbeforeunload = function() {};
		setTimeout(function(){
			document.location.reload();
		}, 250);
	});

and

	jQuery('#submit').click(function(){
		setTimeout(function(){
			window.onbeforeunload = function() {};
			document.location.reload();
		}, 250);
	});

Neither made a difference.

@rgilman
Copy link
Member Author

rgilman commented Dec 4, 2022

I may have a fix. This seems to work in Brave/Firefox/Safari:

	jQuery('#submit').click(function(){
		jQuery(document).ajaxComplete(function(){
			document.location.reload();
		});
	});

@iangilman
Copy link
Member

Cool! I thought we tried something like that before, but I guess not. That's definitely a better solution all around, because we are no longer guessing how long it takes to load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants