Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Javascript cookie integration on FM Pro 6

Featured Replies

  • Newbies

Hi ppl. This is my first post here, so please, be gentle.

I have a cookie implementation on JavaScript working on a web site, so that when a user tries to access a certain page of it with a bookmark, it detects if the cookie exists and if not, then a redirect is performed. However, I've been asked to evolve this solution, so that I could store additional info of the user in the cookie and therefore pass it to a user login database for statistical purposes. This is where the prob begins. Here is a sample code of an html for info detection and cookie storage:

<html>

<head>

<title></title>

<script language="javascript">

function detect () {

internalCode=navigator.appCodeName;

browserName=navigator.appName;

browserVer=navigator.appVersion;

headerInfo=navigator.userAgent;

os=navigator.platform;

document.write("Your browser tye is "+internalCode+"<br>");

document.write("You're browsing using "+browserName+"<br>");

document.write("The Web Browser Version is "+browserVer+"<br>");

document.write("Header: "+headerInfo+"<br>");

document.write("OS platform is "+os);

}

detect ();

function setCookie(NameOfCookie,expiredays)

{

var ExpireDate = new Date ();

ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

document.cookie = (name=NameOfCookie +"; values =" + escape(navigator.appName+"|"+navigator.appVersion+"|"+navigator.platform) +

((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()));

}

setCookie ('cracker',1) // cookie name, days 'till expire = 1

document.write("<br>"+document.cookie) // writes all of the cookie to screen

</script>

</head>

<body>

</body>

</html>

Does anybody know how I can import this info into an DB in FM? I can't get the examples I've got here to work. The mere html fails.

I'm near mental meltdown here.

wink.gif Thx in advance

J

Try this:

document.cookie = "name=" + NameOfCookie + "; values=" + escape(navigator.appName + "|" + navigator.appVersion + "|" + navigator.platform) +

((expiredays == null) ? "" : ("; expires=" + ExpireDate.toGMTString()));


Then on the page you want to use, to add this info to the DB, you would assign the cookie values to <input> tags. You can use either Javascript or CDML ([FMP-Cookie]) to do this.

All the best.

Garry

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.