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?

1
  • Use this : window.location.href='your-url.com'; Commented Feb 12, 2015 at 11:09

2 Answers 2

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?

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.