Can you help me here? I want to show a message every time somebody visits my website! However I want this message to popup only on home page.
Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.
How To Do A JavaScript Pop-Up Welcome Message
To show a message when loading page add this JavaScript before </head>
If you want to show a message before leaving the page:
Code:
<script type="text/javascript">
alert("Your Welcome Message Goes Here");
</script>
If you want to show a message before leaving the page:
Code:
<script type="text/javascript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "Your Message Goes Here";
}
</script>
You may have to consider using cookie to only show welcome message once and not pop-up the window every time user loads that page!
You can try using this JavaScript popup message alert that will only show once per browser session! Just add it to your header above </head> tag
PHP Code:
<script>
var alertmessage="Alert Popup message goes here"
var once_per_session=1
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function alertornot(){
if (get_cookie('alerted')==''){
loadalert()
document.cookie="alerted=yes"
}
}
function loadalert(){
alert(alertmessage)
}
if (once_per_session==0)
loadalert()
else
alertornot()
</script>
Thanks Marcus. Yeah you need to set a cookie to prevent popup alert showing every time you visit the web page. My JavaScript is pretty basic popup welcome message. I think instead of once per session you can set cookie to expire in 24 hours!
It's better to use "jQuery modal popup" as jQuery gives you more control. Or you can simply use HTML5 with a bit of CSS3 to create cool popup form.
Similar Topics:
- Display a message with PHP?
- What are the different JavaScript types?
- JavaScript compressor?
- PHP welcome message?
- How to create php welcome message?
- How to get HTTP status from JavaScript
- Analytics and web-browser with JavaScript disabled?
- Need JavaScript or jQuery notification bar to comply with EU cookie law?
- Anchor link on mouse-over or on hover show a message?
- Hide div using cookie and JavaScript?
User(s) browsing this thread: 1 Guest(s)