Laravel 4- redirect to a route inside javascript code Blade template
11,472
$url=URL::to('foo'); // any other route name, like home, or use URL::route()
<script>
function myFunction()
{
var x;
var r=confirm("Are you sure you want to leave this page ?");
if (r)
{
window.location="{{URL::to('home')}}";
}
...
More info: http://laravel.com/docs/routing
Author by
BaHar AyØub
Updated on June 04, 2022Comments
-
BaHar AyØub almost 2 years
I'm trying to write a simple redirection using javascript and blade engine, and this is an example of what i want to do:
javascript code:
<p>Click the button to go to the home page</p> <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script> function myFunction() { var x; var r=confirm("Are you sure you want to leave this page ?"); if (r==true) { //Redirect to home } else { //stay here } document.getElementById("demo").innerHTML=x; } </script>
when i use return
Redirect::route('home')
it does not work, what is the right syntax to do that, and sorry for my bad english.