Mind blowing SEO improving and Google rank increasing Signature Rotator SEO Tool.

Thread: 

How To Do A JavaScript Pop-Up Welcome Message

Ads
banner
banner
banner
letsplay Offline referral

Posts: 274
Joined: Jul 2013
Reputation: 1

#1
Senior Member
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.
maya Offline referral

Posts: 1,058
Joined: May 2013
Reputation: 34

#2
Posting Freak
To show a message when loading page add this JavaScript before </head>
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>
victor Offline referral

Posts: 638
Joined: Jun 2013
Reputation: 33

#3
Senior Member
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!
marcus_avrelius Offline referral

Posts: 2,424
Joined: May 2013
Reputation: 102

#4
Support Team
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(offsetend))
      }
   }
  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> 
maya Offline referral

Posts: 1,058
Joined: May 2013
Reputation: 34

#5
Posting Freak
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!
surenot Offline referral

Posts: 500
Joined: Jan 2014
Reputation: 16

#6
Senior Member
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.





User(s) browsing this thread: 1 Guest(s)