notebook icon indicating copy to clipboard operation
notebook copied to clipboard

Do not open Notebook in new Tab

Open filipre opened this issue 5 years ago • 9 comments

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é

filipre avatar Oct 18 '18 09:10 filipre

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.

minrk avatar Oct 19 '18 12:10 minrk

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?

filipre avatar Oct 19 '18 13:10 filipre

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.

00Kai0 avatar Oct 20 '18 08:10 00Kai0

hi, about current release, is there a way to set in config without changing custom.js ?

ttpro1995 avatar Mar 02 '20 04:03 ttpro1995

hi, about current release, is there a way to set in config without changing custom.js ?

Did you manage to do this?

StevenGarcia-CG avatar Mar 26 '20 11:03 StevenGarcia-CG

%matplotlib inline it works and graph is appear on jupyter notebook and not open the seprate tab

Talha-Naeem avatar Apr 14 '20 11:04 Talha-Naeem

@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

eliasffyksen avatar Apr 19 '20 07:04 eliasffyksen

If using a docker container, place the file (COPY) in /root/.jupyter/custom/custom.js prior to launching the notebook server.

kliment-slice avatar Aug 22 '22 22:08 kliment-slice

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

jtpio avatar Jun 24 '23 06:06 jtpio