Question

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.

Was it helpful?

Solution

$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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top