Is there a way to click button and open a new link in a new tab?

Similar to this, but make it a button.

'Click <a href="https://panel.holoviz.org/reference/index.html" target="_blank"'>here</a> for docs!'

image

If you want it in the same window use

import panel as pn

code = """
window.location.href="https://panel.holoviz.org"
"""

button = pn.widgets.Button(name="Open Link", button_type="success")
button.js_on_click(code=code)
pn.Column(
    button
).servable()

You can also try the window.open method. It will give you more control. See https://www.w3schools.com/jsref/met_win_open.asp

Cool!

import panel as pn

code = """
window.open("https://panel.holoviz.org")
"""
button = pn.widgets.Button(name="Open Link", button_type="success")
button.js_on_click(code=code)
button

Is what I need

1 Like