Is there a good programmatic way to automatically set a cookie on the highest possible domain?
For example:
sub1.sub2.example.com->example.comsub1.sub2.example.co.uk->example.co.uk
When setting a cookie using document.cookie = ... there is no error when trying to set a cookie for a domain that is "out of scope".
I guess I could iterate through each "level" and try to set a cookie there, so:
sub1.sub2.example.comsub2.example.comexample.comcom
But I would only want the cookie to be set on example.com and not any of the subdomains.
If there was some kind of error, I could start from the bottom and stop when no exception occurs. But as there is no error, that does not work.
Or I guess I could compare document.cookie after each level (also starting from the bottom) and check if my desired value is set. But that also seems quite bad.
Are there any other good solutions?