Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 171397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:58:50+00:00 2026-05-11T12:58:50+00:00

I have a cookie that I did using javascript and to check if it

  • 0

I have a cookie that I did using javascript and to check if it had to be replaced I used ‘onload=checkCookie()’ in the body tag of the HTML, however now I’m trying to place the js in another file and just link it using the tag, but if I do that I can no longer call this function using just ‘onload’ so I was wondering how can I do this? everybody else I’ve asked tells me to leave the code there, but I want to separate my design in layers =S

here’s the js:

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.toGMTString()); }  function checkCookie(){     username=getCookie('username');     if(username!=null && username!=''){         alert('Welcome again '+username+'!');     }else{         username=prompt('Please enter your name:','');         if(username!=null && username!=''){             setCookie('username',username,365);         }     } } 

Everything is inside a file called init.js

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:58:51+00:00Added an answer on May 11, 2026 at 12:58 pm

    Getting the script in a separate file is a good thing. Add the onload function to the script-

    window.onload=checkCookie; //(no parenthesis) and take it out of the html.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 202k
  • Answers 203k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer How about having extract2() return a clean array and run… May 12, 2026 at 8:28 pm
  • Editorial Team
    Editorial Team added an answer Flash "always" uses the html's path as the base for… May 12, 2026 at 8:28 pm
  • Editorial Team
    Editorial Team added an answer What about multiplying by 10^10 and dropping the fractional part?… May 12, 2026 at 8:28 pm

Related Questions

I need to set/get the cookies stored at first.example while browsing second.example , I
I have to login to a page using three parameters, after that I have
I have a single Rails 2.2.2 app that I want to 'share' with multiple
I have an application with a launch page that needs to determine what is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.