This commit is contained in:
Jorijn van der Graaf 2025-11-12 20:45:35 +01:00
commit 9651d84dc4
8 changed files with 239 additions and 207 deletions

View file

@ -102,4 +102,63 @@ int main(){
}
```
This feature allows you to make HTTP requests directly from C++ code running in WebAssembly, which can be useful for communicating with APIs or backend services.
This feature allows you to make HTTP requests directly from C++ code running in WebAssembly, which can be useful for communicating with APIs or backend services.
# Location Pathname Access
The library now provides access to the current page's pathname through the `GetPathNameString()` function:
```cpp
import Crafter.CppDOM;
using namespace Crafter::CppDOMBindings;
int main(){
// Get the current page's pathname
std::string path = GetPathNameString();
// Use the path
HtmlElementView body("body");
body.SetInnerHTML("Current path: " + path);
}
```
# PopState Event Handling
The library supports handling the `popstate` event for navigation history changes:
```cpp
import Crafter.CppDOM;
using namespace Crafter::CppDOMBindings;
int main(){
// Add a listener for popstate events
auto popStateId = AddPopStateListener([]() {
// This will be called when the user navigates back/forward
std::string path = GetPathNameString();
HtmlElementView body("body");
body.SetInnerHTML("Navigated to: " + path);
});
// Later, remove the listener if needed
// RemovePopStateListener(popStateId);
}
```
# History PushState Functionality
The library provides access to the `history.pushState` API for manipulating browser history:
```cpp
import Crafter.CppDOM;
using namespace Crafter::CppDOMBindings;
int main(){
// Push a new state to the browser history
PushState("{\"page\": \"about\"}", "About Page", "/about");
// This will modify the browser URL without reloading the page
// and can be combined with popstate event handling
}
```
These features allow you to build single-page applications with proper URL handling and navigation state management.