Genie Discord forum
![Author Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
I would like to redirect pages using a button with this function in javascript:
window.location.replace( "url", );
![Author Avatar](https://cdn.discordapp.com/avatars/743412727464067154/bc30abeb49653e9978c0f7c90f4486a8.png?size=512)
where do you want to put it? Are you writing your page in Julia or in HTML? you can add scripts with script()
![Author Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
I'm using Stipple.jl. The idea would be that when you click on a button, you perform a certain validation and redirect to another page of the application. I tried with the redirect method, but I was successful.
![Author Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
I thought about the solution in this script, but I don't know if it would be the best solution.
![Author Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
I think about doing this redirection in the control layer.
![Author Avatar](https://cdn.discordapp.com/avatars/743412727464067154/bc30abeb49653e9978c0f7c90f4486a8.png?size=512)
Right now I can think of two ways of doing this...you do it all inside a route
, like
route("/validate_and_redirect") do
if validate() # replace with your validation function
redirect("/success_page")
else
redirect("/error_page")
end
end
or you define a redirect function to be triggered by a button.
function ui()
[
btn("Redirect", @click("redirectTo('/new_path')")),
h1("Average of random numbers"),
{{msg}},
script("function redirectTo(url) { window.location.replace(url); }")
]
end
Another way would be to trigger the javascript redirect from the backend after validation, but I'm not sure how to go about it.