mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-15 19:21:38 +00:00
LibWeb: Allow reloading the current page with location.reload()
This commit is contained in:
parent
71007f6ebb
commit
3b11e471bd
Notes:
sideshowbarker
2024-07-19 06:28:58 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3b11e471bd5
5 changed files with 32 additions and 3 deletions
|
@ -3,12 +3,14 @@
|
|||
<head>
|
||||
<title>window.location test</title>
|
||||
<style>
|
||||
#clickme { background-color: red; color: yellow; }
|
||||
#set_href { background-color: red; color: yellow; }
|
||||
#reload { background-color: blue; color: #ccc; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<pre></pre>
|
||||
<div id="clickme">Click me to navigate away!</div>
|
||||
<div id="set_href">Click me to set location.href!</div>
|
||||
<div id="reload">Click me to call location.reload()!</div>
|
||||
<script>
|
||||
var pre = document.querySelectorAll("pre")[0];
|
||||
pre.innerHTML += "href: " + location.href + '\n';
|
||||
|
@ -19,9 +21,13 @@
|
|||
pre.innerHTML += "hash: " + location.hash + '\n';
|
||||
pre.innerHTML += "search: " + location.search + '\n';
|
||||
|
||||
document.getElementById("clickme").addEventListener("mousedown", function() {
|
||||
document.getElementById("set_href").addEventListener("mousedown", function() {
|
||||
window.location.href = 'http://serenityos.org/';
|
||||
});
|
||||
|
||||
document.getElementById("reload").addEventListener("mousedown", function() {
|
||||
window.location.reload();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -45,6 +45,8 @@ LocationObject::LocationObject()
|
|||
put_native_property("hash", hash_getter, nullptr);
|
||||
put_native_property("search", search_getter, nullptr);
|
||||
put_native_property("protocol", protocol_getter, nullptr);
|
||||
|
||||
put_native_function("reload", reload);
|
||||
}
|
||||
|
||||
LocationObject::~LocationObject()
|
||||
|
@ -110,6 +112,13 @@ JS::Value LocationObject::protocol_getter(JS::Interpreter& interpreter)
|
|||
return JS::js_string(interpreter, builder.to_string());
|
||||
}
|
||||
|
||||
JS::Value LocationObject::reload(JS::Interpreter& interpreter)
|
||||
{
|
||||
auto& window = static_cast<WindowObject&>(interpreter.global_object());
|
||||
window.impl().did_call_location_reload({});
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ public:
|
|||
private:
|
||||
virtual const char* class_name() const override { return "LocationObject"; }
|
||||
|
||||
static JS::Value reload(JS::Interpreter&);
|
||||
|
||||
static JS::Value href_getter(JS::Interpreter&);
|
||||
static void href_setter(JS::Interpreter&, JS::Value);
|
||||
|
||||
|
|
|
@ -119,4 +119,15 @@ void Window::did_set_location_href(Badge<Bindings::LocationObject>, const String
|
|||
view->load(new_href);
|
||||
}
|
||||
|
||||
void Window::did_call_location_reload(Badge<Bindings::LocationObject>)
|
||||
{
|
||||
auto* frame = document().frame();
|
||||
if (!frame)
|
||||
return;
|
||||
auto* view = frame->html_view();
|
||||
if (!view)
|
||||
return;
|
||||
view->reload();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
void set_timeout(JS::Function&, i32);
|
||||
|
||||
void did_set_location_href(Badge<Bindings::LocationObject>, const String& new_href);
|
||||
void did_call_location_reload(Badge<Bindings::LocationObject>);
|
||||
|
||||
private:
|
||||
explicit Window(Document&);
|
||||
|
|
Loading…
Reference in a new issue