1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-03 00:52:12 +00:00

Browser: Open links with target="_blank" in new tab

This commit is contained in:
Linus Groh 2020-04-24 13:06:17 +01:00 committed by Andreas Kling
parent 061205b3b3
commit 896decd4d5
3 changed files with 28 additions and 21 deletions

View file

@ -133,11 +133,16 @@ Tab::Tab()
update_bookmark_button(url.to_string());
};
m_html_widget->on_link_click = [this](auto& url, auto&) {
if (url.starts_with("#")) {
m_html_widget->scroll_to_anchor(url.substring_view(1, url.length() - 1));
m_html_widget->on_link_click = [this](auto& href, auto& target) {
if (href.starts_with("#")) {
auto anchor = href.substring_view(1, href.length() - 1);
m_html_widget->scroll_to_anchor(anchor);
} else {
m_html_widget->load(m_html_widget->document()->complete_url(url));
auto url = m_html_widget->document()->complete_url(href);
if (target == "_blank")
on_tab_open_request(url);
else
m_html_widget->load(url);
}
};