首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C#代码后面的Javascript仅在Google中刷新

C#代码后面的Javascript仅在Google中刷新
EN

Stack Overflow用户
提问于 2014-07-16 17:10:01
回答 1查看 153关注 0票数 0

我的网站有一个asp.net按钮来发布值到外部网站,它在IE和火狐中正常工作。它重定向回Chrome的同一页。

代码语言:javascript
运行
复制
    using (WebClient client = new WebClient())
    {
        HttpContext.Current.Response.Write(string.Format("<body onload=document.forms[0].submit();window.location=\"{0}\";>", "Dashboard.aspx"));
        HttpContext.Current.Response.Write(string.Format("<form name=\"Form\" target=_blank method=post action=\"{0}\">", URL));
        HttpContext.Current.Response.Write(string.Format("<input type=hidden name=\"fname\" value=\"{0}\">", FirstName));
        HttpContext.Current.Response.Write(string.Format("<input type=hidden name=\"lname\" value=\"{0}\">", LastName));
        HttpContext.Current.Response.Write(string.Format("<input type=hidden name=\"id\" value=\"{0}\">", ID));
        HttpContext.Current.Response.Write(string.Format("<input type=hidden name=\"tier\" value=\"{0}\">", tier));
        HttpContext.Current.Response.Write(string.Format("<input type=hidden name=\"promo_code\" value=\"{0}\">", promoCode));
        HttpContext.Current.Response.Write(string.Format("<input type=hidden name=\"login_key\" value=\"{0}\">", hashedKey));
        HttpContext.Current.Response.Write("</form>");
        HttpContext.Current.Response.Write("</body>");
    }

所需的行为是打开一个新的选项卡或窗口,加载外部站点,并通过POST传递参数。

当前行为只是页面刷新。这是众所周知的Chrome问题吗?我的猜测是它阻止了javascript,因为它认为它正在被“注入”。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-16 17:43:24

我猜你在发布表单和更改网址之间有一场比赛。

不需要window.location.href。提交表格就足够了。此外,您可能应该正确引用这些属性,以查看这是否有帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24786746

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档