.NET MVC里如何在服务器端执行JS:
三种解决方案:
1.直接返回JavaScript.
public
ActionResult XXXAction1()
{
return
JavaScript(
"alert('Hello World')"
);
}
2.空白页面上输出文本内容.
public
ActionResult XXXAction1()
{
return
Content(
"alert('Hello World')"
,
"application/javascript"
);
//或者 return Content("alert('Hello World')","appliation/x-javascript");
}
3.使用Response.Write().
Response.Write("<script type='text/javascript'>parent.location.href = '" + url + "';</script>");//(可以用来实现在iframe中跳转到指定页面.)
转载地址:https://www.cnblogs.com/52XF/p/3740318.html