Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 JavaScript: Set cookie even after HTML output Jump to:  
Category: >> JavaScript >> Set cookie even after HTML output Bookmark and Share

<< lastnext >>

Snippet Name: Set cookie even after HTML output

Description: Function that allows a Javascript cookie to be set after HTML has been
output to the page.

Comment: (none)

Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: March 01st, 2009

< s c r ipt type="text/javascript">
 
FUNCTION JSSetCookie($CName,$CValue,$CExpr=FALSE){ 
// $CName is the name of the cookie 
// $CValue is the value to be stored in the cookie 
// $CXpr is in years 
// This function will allow cookies to be set even after 
// HTML has been printed on the page.  It is a supplement to the 
// SetCookie function when you have to output text before a cookie is set. 
 
IF($CExpr!=FALSE){ 
$CookieString="astr= '$CName' + '=' + '$CValue' + ';expires=' + expr + ';path=/';"; 
$Cookie.="\n<script language=\"javascript\">\n"; 
$Cookie.='function makeYearExpDate(yr){ 
var expire = new Date(); 
expire.setTime(expire.getTime() + ((yr *365) *24 * 60 * 60 * 1000)); 
expire = expire.toGMTString() 
return expire 
} 
expr =makeYearExpDate('.$CExpr.');'; 
$Cookie.="\n".$CookieString."\n"; 
$Cookie.="document.cookie=astr;\n</script>\n"; 
}ELSE{ 
$Cookie.="\n<script language=\"javascript\">\n"; 
$Cookie.="document.cookie='$CName=$CValue;path=/';"; 
$Cookie.="\n</script>\n"; 
} 
echo $Cookie; 
}
 
</script>


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 96 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?