我试图使用javascript和刀片引擎编写一个简单的重定向,这是我想要做的一个例子:
javascript代码:
<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>
当我使用return Redirect::route('home')
时,它不起作用,这样做的正确语法是什么,对不起我的英语不好。
答案 0 :(得分:6)
$网址= URL ::到( '富'); //任何其他路由名称,如home,或使用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')}}";
}
...