Make a Popup/Alert Window in a html with a "dont show again" option
How to make a popup in HTML? Different methods - Installation & Integration - Popupsmart Community
Function for pop up message in HTML
HTML Code for Pop-up message
What is the HTML tag for popups?
How to create a popup in HTML with CSS?
How to make a popup card in HTML?
Videos
Unfortunately, you can't do this through a typical JavaScript alert box. You'll need to build you own modal popup to simulate an alert box. jQuery's plugin jQuery UI has a really nice built-in function for this, and I'll use this in my example.
To give the user the option of not showing a window again, you need to make use of localStorage. You would need to create a condition that checks for whether a localStorage item is set. If it is not, display the modal, if it is, hide the modal:
if (!localStorage.hideAlert) {
$(function() {
$("#dialog").dialog();
});
}
else {
$("#dialog").css("display", "none");
}
In the modal itself, you would have a 'No' button that adds the relevant value to localStorage:
<div id="dialog" title="Show Again?">
<p>Would you like to show this dialog again?</p>
<button name="yes" class="yes">Yes</button>
<button name="no" class="no">No</button>
</div>
$(".yes").on("click", function() {
$("#dialog").dialog("close");
});
$(".no").on("click", function() {
localStorage.setItem('hideAlert', true);
$("#dialog").dialog("close");
});
I've created a working example showcasing this here.
This way, all of your code can reside within a single file, though remember that you'll still need to include the external jQuery UI JavaScript, and optional CSS:
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
Hope this helps! :)
In the example below, every popup window has a "Don't Show This Again" button.
Main document:
Code:
<HTML>
<Head>
<Script Language=JavaScript>
var expDate = new Date();
expDate.setTime(expDate.getTime()+365*24*60*60*1000); // one year
function setCookie(isName,isValue,dExpires){
document.cookie = isName+"="+isValue+";expires="+dExpires.toGMTString();
}
function getCookie(isName){
cookieStr = document.cookie;
startSlice = cookieStr.indexOf(isName+"=");
if (startSlice == -1){return false}
endSlice = cookieStr.indexOf(";",startSlice+1)
if (endSlice == -1){endSlice = cookieStr.length}
isData = cookieStr.substring(startSlice,endSlice)
isValue = isData.substring(isData.indexOf("=")+1,isData.length);
return isValue;
}
function initPopups(){
if (!getCookie('pop1'))
{popWin1 = window.open("1/pop1.html","","width=200,height=150,top=50,left=400")}
if (!getCookie('pop2'))
{popWin2 = window.open("1/pop2.html","","width=200,height=150,top=50,left=180")}
}
window.onload=initPopups;
</Script>
</Head>
<Body>
</Body>
The popup files are in a folder named 1
pop1.html:
Code:
<HTML>
<Body>
<input type=button value="Don't show again" onclick="opener.setCookie('pop1',0,opener.expDate);self.close()">
</Body>
</HTML>
pop2.html:
Code:
<HTML>
<Body>
<input type=button value="Don't show again" onclick="opener.setCookie('pop2',0,opener.expDate);self.close()">
</Body>
</HTML>
If you don't care much about layout of this pop-Up, just use window.confirm()
You can build this into your HTML form like this:
<html>
<script>
function checkForm() {
var message = "You entered following data:\n" +
"Car name: " + document.getElementById('cn').value + "\n" +
"Car color: " + document.getElementById('cc').value + "\n" +
"Is this correct?";
if (window.confirm(message))
document.getElementById("carform").submit();
}
</script>
<form id="carform" target="...">
Car name: <input type="text" name="carname" id="cn"/><br/>
Car color: <input type="text" name="carcolor" id="cc"/><br/>
<input type="button" value="submit" onclick="checkForm()"/>
</form>
</html>
EDIT To compare the entered values to the ones you have stored in your SQL database, you have to use PHP. You could realize it for example like this:
<html>
<script>
function checkForm() {
<?php
//Query the current databse values and store them for example in $carcolor $carname
echo 'var currentCarName = "' . $carname . '"';
echo 'var currentCarColor = "' . $carcolor . '"';
?>
var message = "You entered following data:\n" +
"Car name: " + document.getElementById('cn').value + "\n" +
" Old name: " + currentCarName + "\n" +
"Car color: " + document.getElementById('cc').value + "\n" +
" Old color: " + currentCarColor + "\n" +
"Is this correct?";
if (window.confirm(message))
document.getElementById("carform").submit();
}
</script>
<form id="carform" target="...">
Car name: <input type="text" name="carname" id="cn"/><br/>
Car color: <input type="text" name="carcolor" id="cc"/><br/>
<input type="button" value="submit" onclick="checkForm()"/>
</form>
</html>
There's no native function for making a pop up message show up loading HTML. However there is FancyBox which does exactly this.
http://fancybox.net/
Look at this question and this blog for more information on how to do this