最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the equivalent code of `Response.Redirect("~abc.aspx") in java script? - Stack Overflow

programmeradmin0浏览0评论

What is the equivalent code of Response.Redirect(~/Account/Login.aspx"); in javascript?

I tried : window.location="~/Account/Login.aspx" but the ~ is not accepted in javascript. so, what is the alternative code?

Note: the javascript script is made in the server side in the Page_Load method by using ClientScript.RegisterClientScriptBlock.

What is the equivalent code of Response.Redirect(~/Account/Login.aspx"); in javascript?

I tried : window.location="~/Account/Login.aspx" but the ~ is not accepted in javascript. so, what is the alternative code?

Note: the javascript script is made in the server side in the Page_Load method by using ClientScript.RegisterClientScriptBlock.

Share Improve this question asked Jul 11, 2011 at 11:31 French BoyFrench Boy 1,4913 gold badges18 silver badges23 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 13

use

window.location='<%= ResolveUrl("~/Account/Login.aspx") %>'

EDIT: if it is created in codebehind, then use

string.Format("window.location='{0}';", ResolveUrl("~/Account/Login.aspx"))

Try this:

window.location='<%= ResolveUrl("~/Account/Login.aspx") %>';

The ~ is replaced by the application URL in .NET, but this is not done in Javascript.

Try:

Page.RegisterClientScriptBlock(typeof(_Default), "Redirect", "document.location.href = '" + ResolveUrl("~/Account/Login.aspx") + "';", true);

I would ask as to why you are doing a client-side redirect from the server-side though? Would it not be more appropriate to do a Response.Redirect instead?

发布评论

评论列表(0)

  1. 暂无评论