Is there a way to cause a programmatically generated url to open in a new browser tab or window from an IPython notebook cell?
Upon execution of the notebook cell the result should be the opening of a new tab or window pointing to the generated link.
NOTE: When I just return an IPython.core.display.HTML instance with a hyperlink the link is broken. If the url is copied and pasted into a browser window it is valid.
3.1.Double-click on the Jupyter Notebook desktop launcher (icon shows [IPy]) to start the Jupyter Notebook App. The notebook interface will appear in a new browser window or tab. A secondary terminal window (used only for error logging and for shut down) will be also opened.
When you work with your standard browser, you can use the webbrowser
module:
import webbrowser
# generate an URL
url = 'https://' + 'www.google.com'
webbrowser.open(url)
You can use javascript to open the link client-side. It should work on remote servers because the tab-opening occurs in the user's browser instead of on the server.
This simple code snippet uses window.open()
to open a new tab/popup with your desired url.
from IPython.display import Javascript
def window_open(url):
display(Javascript('window.open("{url}");'.format(url=url)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With