Skip to content
A Corona HTML5 Cookie Plugin
JavaScript Lua
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
demo
icons
plugin
LICENSE
README.md

README.md

logo Corona HTML5 Cookie Plugin

A basic plugin for setting, getting, and deleting cookies inside your Corona HTML5 apps.

Browser Tests

chrome ie firefox safari opera
pass untested pass pass untested

Windows browser unconfirmed.

Installation

  • Download the Corona HTML5 Cookie Plugin repository.

  • Move plugin/cookie.lua and plugin/cookie_js.js to the root of your HTML5 project.

  • Require the plugin in your code where you need it.

local cookie = require("cookie")

API

set

Set the cookie data.

cookie.set(name, value[, expiryDays])

Arguments

Name Description Type Required
name The name of the cookie. String Y
value The value of the cookie. String Y
expiryDays Days till expiration. Otherwise, lasts until deleted. Number N

Returns

The String 'set' on success.

Example

local result = cookie.set("username", "develephant", 1) -- expire in 1 day

print(result) --> set

get

Get the cookie data.

cookie.get(name)

Arguments

Name Description Type Required
name The name of the cookie. String Y

Returns

The cookie value as a String. If no cookie data exists, returns empty String.

Example

local username = cookie.get("username")

print(username) --> develephant

delete

Delete the cookie data.

cookie.delete(name)

Arguments

Name Description Type Required
name The name of the cookie. String Y

Returns

The String 'deleted' on success.

Example

local result = cookie.delete("username")

print(result) --> deleted

Demo

In the demo directory is a Corona project that you can build for HTML5 testing.

The demo does have some debug output that prints to the browser console. The plugin in the plugin directory does not output any debug info.

Notes

  • In the demo, the loading bar is not shown because of the black background. Hopefully this will be a build setting option in the future.

  • Reload the browser after setting a cookie to see that it has saved the cookie.

  • You can also view the cookie data using the Google Chrome Developer Tools window. Click the Application tab, and then Cookies (on the left side menu).


©2018 C. Byerley (develephant)

You can’t perform that action at this time.