notebook
notebook copied to clipboard
Do not open Notebook in new Tab
Hi,
Every time I click on a *.ipynb
file via the web browser, it opens the file in a new tab. Usually I end up in a situation where multiple instances of the same notebook are open. Is it possible to prevent Jupyter doing so? I would prefer the native "Open Link in a new Tab" functionality if I really need it. A quick solution would be to remove all target="_blank"
but is there also an option for that?
Greetings René
Yes, it is possible. In your custom.js
, you can set Jupyter._target = '_self'
instead of the default _blank
:
require(["base/js/namespace"], function (Jupyter) {
Jupyter._target = '_self';
});
This overrides the default global "open in new tab" behavior.
Awesome. That what I was looking for. However, it looks like creating a custom.js
is not so straight forward if you use conda environment. I created a file in ~/.jupyter/custom/custom.js
but this did not work.
jupyter
is pointing to /Users/<user>/anaconda/envs/<my-environment>/bin/jupyter
. I found a custom.js
file in ▸ anaconda ▸ envs ▸ <my-environement> ▸ lib ▸ python3.6 ▸ site-packages ▸ jupyter_core ▸ tests ▸ dotipython ▸ profile_default ▸ static ▸ custom
but this seems not to be the right path as well.
Do you have an idea where the custom.js
could be located in a conda environment?
root@localhost:/home/teacher/.jupyter/custom# ls
bg1.jpg bg.jpg current_theme.txt custom.css custom.js fonts
root@localhost:/home/teacher/.jupyter/custom# cat custom.js
require(["base/js/namespace"], function (Jupyter) {
Jupyter._target = '_self';
});
When I set custom.js
file in teacher's home dir and login as teacher then it works.
By the way, I use jupyterhub
.
hi, about current release, is there a way to set in config without changing custom.js ?
hi, about current release, is there a way to set in config without changing custom.js ?
Did you manage to do this?
%matplotlib inline it works and graph is appear on jupyter notebook and not open the seprate tab
@StevenGarcia-CG Hi, i found out that for some reason it does not get loaded for the first time the content is loaded, so it will work, but you have to wait for about a minute or two before it does, so that jupyter loads the content again. This is a very dirty but quick fix, that works (using jquery to change the targets of all links)... custom.js:
$('a').attr('target', '_self');
require(["base/js/namespace"], function (Jupyter) {
Jupyter._target = '_self';
});
Not sure if this will break anything important, but i will continue to test it
If using a docker container, place the file (COPY) in /root/.jupyter/custom/custom.js
prior to launching the notebook server.
In Notebook 7, there could be a user setting to open the notebook in a new tab true
by default, but that could be modified via the Settings Editor.
The value of the setting could then be used here:
https://github.com/jupyter/notebook/blob/7f1a2f49ef77abdca2dd22c42a4fcfb8e6890a11/packages/docmanager-extension/src/index.ts#L55