1
$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);

The Url call is supposed to call actionOverWrite() in DefaultController. But this is not happening. How to call action from view?

Sujata
  • 732
  • 2
  • 8
  • 18

2 Answers2

4

You could simply try :

$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);

Read more about js redirection : How to redirect to another webpage in JavaScript/jQuery?

Community
  • 1
  • 1
soju
  • 24,553
  • 3
  • 65
  • 68
1

Or try this

$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);
arogachev
  • 32,610
  • 6
  • 111
  • 116
vitalik_74
  • 4,463
  • 2
  • 16
  • 26