$this->registerJS(
'var ok = confirm("File already exists!! Do you want to overwrite file");
if(ok)
{
"'.Url::toRoute('default/over-write?id=1').'";
}
else
{
"'.Url::toRoute('default/over-write?id=0').'";
};',View::POS_READY);
Url调用应该在DefaultController中调用actionOverWrite()。但这不会发生。如何从视图中调用操作?
答案 0 :(得分:4)
您可以尝试:
$this->registerJS('
var ok = confirm("File already exists!! Do you want to overwrite file");
window.location.replace("'.Url::toRoute('default/over-write').'" + "?id=" + (ok ? 1 : 0));
', View::POS_READY);
阅读有关js重定向的更多信息: How to redirect to another webpage in JavaScript/jQuery?
答案 1 :(得分:1)
或试试这个
$this->registerJS(
'var url = "'.Url::toRoute('default/over-write?id=').'";
if(confirm("File already exists!! Do you want to overwrite file"))
{
window.location.href = url + '1';
}
else
{
window.location.href = url + '0';
};',View::POS_READY);