xowf::test_item::Answer_manager method prevent_multiple_tabs (public)

 <instance of xowf::test_item::Answer_manager[i]> prevent_multiple_tabs \
    [ -cookie_name cookie_name ]

Defined in packages/xowf/tcl/test-item-procs.tcl

Prevent answering the same survey from multiple, concurrently open tabs.

Switches:
-cookie_name (optional, defaults to "multiple_tabs")

Testcases:
No testcase defined.
Source code:
template::add_body_script -script [subst {
  var cookieLine = document.cookie.split('; ').find(row => row.startsWith('$cookie_name='));
  var cookieValue = (cookieLine === undefined) ? 1 : parseInt(cookieLine.split('=')\[1\]) + 1;
  // console.log("cookie $cookie_name " + cookieValue);
  if (cookieValue > 1) {
    alert('Already open!');
    window.open("about:blank""_self").close();
  }
  document.cookie = "$cookie_name=" + cookieValue;
  // console.log("START finished -> " + document.cookie);

  window.onunload = function () {
    var cookieLine = document.cookie.split('; ').find(row => row.startsWith('$cookie_name='));
    var cookieValue = (cookieLine === undefined) ? 0 : parseInt(cookieLine.split('=')\[1\]) - 1;
    document.cookie = "$cookie_name=" + cookieValue;
    // console.log("UNLOAD finished -> " + document.cookie);
  };
}]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: