How to open a web url in new tab

Hi All,

I am trying to open a web url on a click of new tab. But when i try to do so i get " www.airbnb.com(given url) refused to connect."

Can anyone help or guide me to solve this?

import flask
import dash
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
from dash.dependencies import Output, Input, State
from dash.exceptions import PreventUpdate
from datetime import datetime
from sharedstate import MainConfig
from app import app
from apps import dbcontrol, mappView

    html.Div([
        dcc.Location(id='url', refresh=False),
        dcc.Tabs(id="tabs", value='tab-1', children=[
            dcc.Tab(label='Database control', value='tab-1'),
            dcc.Tab(label='mapp View', value='tab-2'),
        ]),
        html.Div(id='tabs-content')
    ]),

@app.callback(Output(‘tabs-content’, ‘children’),
[Input(‘tabs’, ‘value’)])
def render_content(tab):
if tab == ‘tab-1’:
return html.Div([
html.Div(dbcontrol.layout),
])
elif tab == ‘tab-2’:
return html.Div([
html.Iframe(
width=1300,
height=820,
src=‘https://www.airbnb.com/’,
),
html.Div(mappView.layout),
]),

mappView.layout
import dash_core_components as dcc
import dash_bootstrap_components as dbc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from os import listdir, makedirs
from os.path import isfile, join
import shutil
import time
from datetime import datetime

from datetime import datetime as dt

from sharedstate import PullToDb

from app import app

layout = html.Div([
html.Div(id=‘div-signal-page-load’, style={‘display’: ‘none’}),
html.Div(id=‘div-signal-refresh’, style={‘display’: ‘none’}),
])

Hi,
I don’t understand why you are using dcc.location but never assigning the “href” property to it?

Hi,

I just tried that logic. Please consider that line as disable logic.
#dcc.Location(id=‘url’, refresh=False),

Is it related to html.Iframe refferrerpolicy ?
As my application address is “http://localhost:8050/” and i am accessing “http://www.airbnb.com” on tab
which in result conflicting with “same origin” policy.

Try this

app.clientside_callback(
“”"
function(clicks) {
if (clicks) {
windows.open(“you link”, “_blank”);
}
}
“”"),
Output(‘hidden-div’, ‘children’),
Input(‘btn’, ‘n_clicks’),
)

I pass the link to the input and add it to the javascript function)

Hi,

I tried as you recommended but in my initial code and below one i found same issue.
My guess is issue/limitation due to reference policy because of that it is not working.

layout = html.Div([
html.Div(id=‘hidden-content-global2’),
html.Img(id=‘printingGlobal2’, src=‘assets/Tabs Images/PrintIcon.svg’, width=‘100’, height=‘60’, style={‘padding’: ‘10px 5px’}),
html.Iframe(name=“hiddencontentglobal3”, width=1280, height=780),
])

app.clientside_callback(
“”"
function(n_intervals) {
if (n_intervals > 0) {
window.open(“https://www.espncricinfo.com/","hiddencontentglobal3”)
}
}
“”",
Output(‘hidden-content-global2’, ‘children’),
Input(‘printingGlobal2’, ‘n_clicks’),
)