Can someone edit my body tag?

  • 1
  • Question
  • Updated 8 years ago
  • Answered
Hi, I set up some JavaScript and it sets cookies for the user. But, they are setting, but I have to still edit the body tag so it will get the cookie. Any ideas? Can an employee get in the site builder or something and edit the body tag?

The body tag has to be changed to this:

<body onload="set_style_from_cookie()">
Photo of Nathan

Nathan, Champion

  • 3739 Posts
  • 307 Reply Likes
  • undecided

Posted 8 years ago

  • 1
Photo of Michael Joseph

Michael Joseph

  • 4 Posts
  • 0 Reply Likes
Official Response
Hi Nathan,

We don't currently allow the body tag to be modified (either by redefinition, or specifying onload actions).
However, the call to the set_style_from_cookie() function doesn't have to be triggered from the body tag onload event- you can call the function directly from a JavaScript snippet inside an HTML widget.

&lt;script type=&quot;text/javascript&quot;&gt;

I have successfully created a test site (using a slightly modified version of the JavaScript you linked to above) that sets and retrieves cookie data.
This page sets the cookie "test_cookie" to "foo".
This page retrieves the cookie and displays it with a JavaScript alert.

I had to modify the regular expression in the get_cookie() function to get this to work, here's the modified get_cookie function:

function get_cookie ( cookie_name )
var cookie_string = document.cookie ;
if (cookie_string.length != 0) {
var cookie_value = cookie_string.match( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
return decodeURIComponent ( cookie_value[2] ) ;
return '' ;