Conditional logic based on logged in user or embedded?

Is there a variable that I could access from a notebook that tells me any of these?:

  • current logged in user info
  • notebook is currently embedded

I’d like to apply some conditional logic based on whether the notebook is embedded on a public website or accessed directly by me in but I don’t know if it’s possible

1 Like

I don’t know the answers to your questions but I can suggest an approach that might get you roughly what you want. The idea is to use a query string, as suggested in this description of Parameterized Notebooks.

For example, here’s a link to one of my webpages:

If you follow that link, you should see something like
“Hello WWW!”

Note that I created that webpage by embedding this notebook:

You’ll notice the difference in who’s greeted. The key is that the code for embedding the iframe looks like so:

<iframe width="100%" height="109" frameborder="0"  src=""></iframe>

Note that I’ve included locale=web as part of the query string. If you look at the notebook, you’ll notice that I’m adjusting the greeting based on the value of that parameter.

You can also embed using the Javascript Runtime:
Then, assuming users get to your page from a link that you control, you can alter the appearance based on that query string. Of course, users might fiddle with the query string, though.


The top level URL html`<a href>`.href can signal where the notebook is at the top level.

For getting the current user I don’t think there is a way. I did a huge workaround for federated login. You can somewhat track yourself with a cross* domain cookie, which is the trick for federated login (doesn’t work with safari).

  • probably not even a cross domain cookie as embedded notebooks usually have same origin.