diff --git a/Base/home/anon/www/location.html b/Base/home/anon/www/location.html index 61a42351c69..9405fd93fcc 100644 --- a/Base/home/anon/www/location.html +++ b/Base/home/anon/www/location.html @@ -2,9 +2,13 @@ window.location test + -

+    

+    
Click me to navigate away!
diff --git a/Libraries/LibWeb/Bindings/LocationObject.cpp b/Libraries/LibWeb/Bindings/LocationObject.cpp index 302f64db408..f8199031955 100644 --- a/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -54,9 +54,13 @@ JS::Value LocationObject::href_getter(JS::Interpreter& interpreter) return JS::js_string(interpreter, window.impl().document().url().to_string()); } -void LocationObject::href_setter(JS::Interpreter&, JS::Value) +void LocationObject::href_setter(JS::Interpreter& interpreter, JS::Value value) { - // FIXME: Navigate to a new URL + auto& window = static_cast(interpreter.global_object()); + auto new_href = value.to_string(interpreter); + if (interpreter.exception()) + return; + window.impl().did_set_location_href({}, new_href); } JS::Value LocationObject::pathname_getter(JS::Interpreter& interpreter) diff --git a/Libraries/LibWeb/DOM/Window.cpp b/Libraries/LibWeb/DOM/Window.cpp index adac5c50688..01bf4ca2257 100644 --- a/Libraries/LibWeb/DOM/Window.cpp +++ b/Libraries/LibWeb/DOM/Window.cpp @@ -30,7 +30,10 @@ #include #include #include +#include #include +#include +#include namespace Web { @@ -105,4 +108,15 @@ void Window::cancel_animation_frame(i32 id) GUI::DisplayLink::unregister_callback(id); } +void Window::did_set_location_href(Badge, const String& new_href) +{ + auto* frame = document().frame(); + if (!frame) + return; + auto* view = frame->html_view(); + if (!view) + return; + view->load(new_href); +} + } diff --git a/Libraries/LibWeb/DOM/Window.h b/Libraries/LibWeb/DOM/Window.h index 03d548b71ac..77214a7de69 100644 --- a/Libraries/LibWeb/DOM/Window.h +++ b/Libraries/LibWeb/DOM/Window.h @@ -49,6 +49,8 @@ public: void set_interval(JS::Function&, i32); void set_timeout(JS::Function&, i32); + void did_set_location_href(Badge, const String& new_href); + private: explicit Window(Document&); diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index b54f45f9581..f84af285ec6 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -67,6 +67,7 @@ class EventTargetWrapper; class HTMLCanvasElementWrapper; class HTMLImageElementWrapper; class ImageDataWrapper; +class LocationObject; class MouseEventWrapper; class NodeWrapper; class WindowObject;