Slowly hide success and error message divs and remove the query string from the URL

When you display content based on the presence of a URL query string value. For example " saved successfully" will display the message, fade out after X seconds (2.5 seconds below) and then remove the query string from the address bar to display just this ""
JavaScript • JQuery

Insert the code at the bottom of your page or in your subsequent JS library.

$(document).ready( function() {

	/* fade them out */
	var objs = $('.successmsgdiv,.errormsgdiv');
	if (objs.css('display','block')) { objs.delay(2500).fadeOut('slow');}

	/* remove the query string from the URL */
	var href = window.location.href;
	if(href.indexOf('&smsg=')) {
		var url = href.split('&smsg='); history.pushState(null,null, url[0]);
	} else if(href.indexOf('&emsg=')) {
		var url = href.split('&emsg='); history.pushState(null,null, url[0]);


Written by fbrefere001

Posted by fbrefere001 on Wednesday July 12, 2017