Executing Javascript cells in Jupyter Notebooks

5.8k views Asked by At

I'm seeing some strange behavior using Javascript cells in a (trusted) Jupyter notebook.

For example, I can execute the following cells, intended to fetch the current URL of the notebook.

%%javascript
var kernel = IPython.notebook.kernel;
var thename = window.location.href;
var command = "notebook_url = " + "'"+thename+"'";
kernel.execute(command);

And now I try to access the variable in another cell:

print notebook_url

This works as expected with I run the cells one after another (Shift + Enter), but throws a NameError: name 'notebook_url' is not defined when I try to 'Run All' cells.

How could I get this to work with 'Run All'?

0

There are 0 answers