2

I work in a JupyterHub environment where I use to render applications with voila.

One of this particular applications is supposed to be a kind of Launcher from where a user can launch (open) a particular url web in another chrome tab.

I use the following code:

import ipyvuetify as vue
from ipywidgets import Output
from IPython.display import Javascript

out=Output()
b = vue.Btn(color='primary',children=['open tabs'])
def on_click(widget, event, data):
    # generate an URL
    url_nyt    = "https://www.nytimes.com/"
    url_news   = "https://www.cnn.com"
    with out:
        print('go')
        # VEEEEEEEERRRRY important: inside out
        display(Javascript(f'window.open("{url_nyt}");'))
        print('first')
    with out:
        display(Javascript(f'window.open("{url_news}");'))
        print('second')
# this does not work neither: display(Javascript(f'window.open("{url_nyt}");window.open("{url_news}")'))
        
b.on_event('click', on_click)
display(b,out)

This works only with the first url. What happens is that indeed a new tab opens and the nyt web site opens there but there is no second tab open. Nevertheless in the output widget is possible to see "second" so the second display was run, did not give an error, but did not work.

Any idea why that is like this? Or any workaround? Is it necessary to open the tab in the background? how?

btw, the library webbrowser does not work since this is jupyterHub (in a remote server) and not a local jupyter lab distribution.

thanks

JFerro
  • 3,203
  • 7
  • 35
  • 88
  • Hi @JFerro did you figure out how to solve this? – gokul_uf Aug 26 '22 at 11:43
  • Not yet, actually I put the project asside since I came to the conclusion that with pure python I am not able to do that. (perhpas injecting JS in the python code). But that would go beyond what I pretend. – JFerro Aug 26 '22 at 11:44

0 Answers0