• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.
  • The forums have been upgraded with support for dark mode. By default it will follow the setting on your system/browser. You may override it by scrolling to the end of the page and clicking the gears icon.

Does this cookie script look correct?

stinger608

Dedicated TPU Cruncher & Folder
Joined
Nov 11, 2008
Messages
11,250 (1.85/day)
Location
Wyoming
System Name 2023 Ryzenfall
Processor AMD Ryzen 5800X
Motherboard Asus ROG STRIX B550-F Gaming Wifi
Cooling SilverStone AH240 AIO
Memory 32 gigs G.Skill TridentZ NEO DDR4
Video Card(s) EVGA GTX 1080 FTW Hybrid Gaming
Storage Dual Samsung 980 Pro M2 NVME 4.0
Display(s) Overlord 27" 2560 x 1440
Case Corsair Air 540
Audio Device(s) On board
Power Supply Seasonic modular 850 watt Platinum
Software Windows 10 Pro
Just wondering if this script to include a JavaScript pop up look correct? Kind of new to all of this, so any advice would be much appreciated:respect::toast:

Code:
<script type="text/javascript">
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function checkCookie()
{
username=getCookie('username');
if (username!=null && username!="")
  {
  alert('Welcome back, glad you stopped by '+username+'!');
  }
else
  {
  username=prompt('Please enter your name:',"");
  if (username!=null && username!="")
    {
    setCookie('username',username,365);
    }
  }
}
</script>
 
Javascript pop-up to set cookies? Since you're new to this, I'm going to let you off with a warning. But don't let me catch you in this part of the internet again.
 
As a person not knowledgeable about JavaScript, I am forced to read the valus of the string variables only, and it seems to me that what you want to happen is that once someone logs in, a cookie is placed (duh!) and a pop-up says welcome to that person.
However, a pop-up blocker will probably block the pop-up because many pop-ups are evil (at least on "evil" sites). And if my guess about your goal was correct, then why don't you integrate the welcome message in the web page itself, like this forum is doing? And more importantly, do you actually need JS to place cookies? As a person that is not a web dev I again have to guess, but can't the cookie thing be done via html or whatever?
 
Javascript pop-up to set cookies? Since you're new to this, I'm going to let you off with a warning. But don't let me catch you in this part of the internet again.

:laugh::laugh::laugh:Understood LOL

As a person not knowledgeable about JavaScript, I am forced to read the valus of the string variables only, and it seems to me that what you want to happen is that once someone logs in, a cookie is placed (duh!) and a pop-up says welcome to that person.
However, a pop-up blocker will probably block the pop-up because many pop-ups are evil (at least on "evil" sites). And if my guess about your goal was correct, then why don't you integrate the welcome message in the web page itself, like this forum is doing? And more importantly, do you actually need JS to place cookies? As a person that is not a web dev I again have to guess, but can't the cookie thing be done via html or whatever?


The only thing this is, is a class project. Just making sure that it works is all. And your right Chev it is a pop-up that welcomes the person back again.
 
Back
Top