Is there any way to detect if cookies are blocked by a browser?
I thought I could possibly set a cookie then read it to see if it got set. Unfortunately that doesn’t work as Session.Cookies.Value returns whatever I set until the page is refreshed even thogh cookies in fact blocked by the browser.
Interestingly after futsing around with this I was able to get Session.Cookies.Value to return an empty string without refreshing by testing after sending a request to my database. I could only get that to work if I sent the request from a button then tested again with a test button. Perhaps using a timer would make this approach work.
After a bit more research and testing, I think I understand this a bit better. Setting a cookie and then testing if it was set would not work unless the http header was updated. Refreshing the browser does just that.
Session.Cookies.Value doesn’t check with the browser to see what the value is, but instead just returns the cookies from the header less any cookies removed with session.Cookies.Removed and including any cookies set with session.Cookies.Set since the header was received.
Am I thinking in the right direction now? If that is the case then anything that refreshes the http header after setting a cookie would allow my idea to work, I think. What could be used to refresh the header without doing a refresh? Probably nothing.
For anyone who is interested, here is how I implemented a test for cookies being enabled in my project.
I have a checkbox, cbOptioin, on a login web dialog that says “Remember me”. If they check it, the value changed event runs…
TimerCookies.Mode = timer.ModeSingle
The timer is necessary because the hash tag is not set until after the changed event code above completes. The timer in the dialog has the following action event…
[code]me.Mode = timer.ModeOff
if session.HashTag = “false” then
MsgBox “Cookies are disabled in your browser. To remember you on this computer, you must first enable cookies.”
cbOption.Value = false
I am sure there are ways to do this without a timer, but I find this pretty simple and it works.
I can’t understand the logic behind this
if session.HashTag = "false" then
In the cbOption onvalue changed event session.Hashtag gets set to true or false from the js function navigator.cookiesEnabled.
Then in the timer I am checking what session.Hashtag has set. If the js script returned false the cookies have been disabled in the browser, and I let the user know that they cannot be remembered on that computer with that browser.
does “session.HashTag” as co-relation with "location.hash " ?
@ronaldo florendo does “session.HashTag” as co-relation with "location.hash " ?
oh wow. This is very useful.
I don’t think session.Hashtag is a xojo object.
As I am beginning to understand hashtags the js command location.hash sets a hashtag in the page URL…
I just found out how to remove the hashtag that I just created for my test…
Using the hashtag is useful for a quick job, but for bigger jobs involving the browser DOM I would highly recommend getting into the WebSDK. Examples and documentation can be found at