1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:07:35 +00:00

Browser: An anchor link should open in a new tab when required

Previously, clicking on an anchor link (href="#section1")
would always scroll to it on the current page, even if control was
held or the target="_blank" attribute was set. This fixes that
behaviour, and the link will always open in a new tab if required.
This commit is contained in:
FalseHonesty 2020-05-22 21:35:09 -04:00 committed by Andreas Kling
parent e5c2e53739
commit 78412ee76d

View file

@ -146,16 +146,18 @@ Tab::Tab()
}; };
m_html_widget->on_link_click = [this](auto& href, auto& target, unsigned modifiers) { m_html_widget->on_link_click = [this](auto& href, auto& target, unsigned modifiers) {
if (target == "_blank" || modifiers == Mod_Ctrl) {
auto url = m_html_widget->document()->complete_url(href);
on_tab_open_request(url);
} else {
if (href.starts_with("#")) { if (href.starts_with("#")) {
auto anchor = href.substring_view(1, href.length() - 1); auto anchor = href.substring_view(1, href.length() - 1);
m_html_widget->scroll_to_anchor(anchor); m_html_widget->scroll_to_anchor(anchor);
} else { } else {
auto url = m_html_widget->document()->complete_url(href); auto url = m_html_widget->document()->complete_url(href);
if (target == "_blank" || modifiers == Mod_Ctrl)
on_tab_open_request(url);
else
m_html_widget->load(url); m_html_widget->load(url);
} }
}
}; };
m_link_context_menu = GUI::Menu::construct(); m_link_context_menu = GUI::Menu::construct();