0

I have problem with javascript code inside my controller. The below code working fine with all the browser(IE,Chrome and Safari) but not in Firefox? It prints the javascript code in the browser. Please help me anyone had the same issue. Thanks in advance.

public ActionResult LogOut()
{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();

    sb.Append("<script type = 'text/javascript'>");
    sb.Append("window.location.href = 'myurl'");
    sb.Append("</script>");

    return JavaScript(sb.ToString());
}

If any other way to do this please share with me.

1
  • What's firebug saying is the type of the response (text/javascript, something else...)? Commented Oct 7, 2013 at 10:50

2 Answers 2

1

Why not just use a Redirect action result to redirect the user to myurl?

Get rid of the StringBuilder logic and just:

return RedirectToAction(yourAction);

if it's an action in the same controller, or:

return Redirect('myurl');

if it's an URL outside the controller.

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

Comments

0

Try returning Content instead of JavaScript:

return Content(sb.ToString());

But if you just need to redirect users, then it's better to use redirect:

return Redirect("myurl");

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.