0

I have this button in javascript .

 <a href="#" onclick="window.location.href = " ' + urlOfNewTask + ' "; return false;">{{"view_task"|translate}}</a>\
All I want to do is to close this modal after I click on it( for this I insert return false) and this button to take me to the link inside the onclick function. The problem is that when I click at the button nothing happens, nor close of the modal nor open the link. Have i done something wrong? Here is the variable :

var urlOfNewTask = mytaskbaseurl + "." + data.taskEscUrl;

7
  • 1
    try without the funky quotes!! "window.location.href = urlOfNewTask; return false;" or "window.location.href = 'urlOfNewTask'; return false;" if urlOfNewTask is a string literal and not some variable Commented Sep 6, 2016 at 10:49
  • here's a tip to writing inline javascript .... write it ... then add quotes around it - if you use single quotes in the script, use double quotes around it, and vice versa ... if you (have to) use both ' and " in the script - then escape the ones you surround the script inside the script Commented Sep 6, 2016 at 10:52
  • No url is a variable Commented Sep 6, 2016 at 10:53
  • then use the first form I said Commented Sep 6, 2016 at 10:53
  • I editred the question Commented Sep 6, 2016 at 12:12

1 Answer 1

1

Change onclick to onclick="window.location.href = 'urlOfNewTask'; return false;"

If urlOfNeTask is variable then try :

onclick="window.location.href = urlOfNewTask; return false;"
Sign up to request clarification or add additional context in comments.

5 Comments

assuming urlOfNewTask is the literal string urlOfNewTask, rather than some global variable (which seems to be the case)
Yes. @JaromandaX you are right. So I updated my answer accordingly
If url is variable and declared global then you can use second answer
Can you add your html and javascript code it will help me solve your problem faster
You can declare var urlOfNewTask globally so it can be accessed by onclick part.

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.