summaryrefslogtreecommitdiff
path: root/Applications/Browser
diff options
context:
space:
mode:
authorFalseHonesty <thefalsehonesty@gmail.com>2020-05-22 21:35:09 -0400
committerAndreas Kling <kling@serenityos.org>2020-05-23 11:53:25 +0200
commit78412ee76d5c6f26b872f935feb91554bc3a61c4 (patch)
tree61c6cb055f56cb6d36704cc2bc23b2c0af57e210 /Applications/Browser
parente5c2e53739dd0b94691b30f3af7892e165bb6436 (diff)
downloadserenity-78412ee76d5c6f26b872f935feb91554bc3a61c4.zip
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.
Diffstat (limited to 'Applications/Browser')
-rw-r--r--Applications/Browser/Tab.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp
index 9b25870706..c6a19f8c83 100644
--- a/Applications/Browser/Tab.cpp
+++ b/Applications/Browser/Tab.cpp
@@ -146,15 +146,17 @@ Tab::Tab()
};
m_html_widget->on_link_click = [this](auto& href, auto& target, unsigned modifiers) {
- if (href.starts_with("#")) {
- auto anchor = href.substring_view(1, href.length() - 1);
- m_html_widget->scroll_to_anchor(anchor);
- } else {
+ if (target == "_blank" || modifiers == Mod_Ctrl) {
auto url = m_html_widget->document()->complete_url(href);
- if (target == "_blank" || modifiers == Mod_Ctrl)
- on_tab_open_request(url);
- else
+ on_tab_open_request(url);
+ } else {
+ if (href.starts_with("#")) {
+ auto anchor = href.substring_view(1, href.length() - 1);
+ m_html_widget->scroll_to_anchor(anchor);
+ } else {
+ auto url = m_html_widget->document()->complete_url(href);
m_html_widget->load(url);
+ }
}
};