Is there a way to get the value of document.URL from a notebook? I am getting a value that’s different from the one displayed in the browser’s address bar, as can be seen in this notebook:
Similar problems are encountered also with location.href or location.
My intent was to read the value of location.hash into a cell value.
document.URL and the other approaches you’re using will fail because Observable notebooks run in an iframe. I don’t see an easy way to read the URL of the containing page since that is likely to go against the same-origin policy. E.g. window.parent.location.href returns SecurityError: Permission denied to get property "href" on cross-origin object. Actually, see below!
Edit: Oh, I just realized that you said you only want the location.hash. If you’re planning to parse that info and use it as user-provided data in your notebook, an alternate approach is to use the query parameters (stuff after ? in the URL) as shown in these notebooks:
EDIT 2: Hmm, the notebooks above provide a solution to part of the original question: document.baseURI will return the URL of the containing page, but unfortunately it does not seem to contain the URL hash…