背后的C#代码中的Javascript仅在Google Chrome中刷新 - c#

我的网站上有一个asp.net按钮,可以将值发布到外部网站,该网站可以在IE和Firefox中正常运行。它将重定向回到Chrome中的同一页面。

    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。

参考方案

我的猜测是您在发布表单和更改URL之间存在竞争。

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

Javascript-从当前网址中删除查询字符串 - javascript

单击提交按钮后,我需要从网址中删除查询字符串值。我可以用jQuery做到这一点吗?当前网址:siteUrl/page.php?key=value 页面提交后:siteUrl/page.php 实际上,我已经从另一个带有查询字符串的页面着陆到当前页面。我需要在页面首次加载时查询字符串值以预填充一些详细信息。但是,一旦我提交了表格,我就需要删除查询字符串值。我已…

Mongo汇总 - javascript

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …

JavaScript中的字符串评估函数 - javascript

            JavaScript中是否有任何内置函数,例如Python中的eval内置函数?注意:eval函数将方程式作为字符串并返回结果。例如,假设变量x为2,则eval("2x+5")返回9。 参考方案 是的,JavaScript中也有eval函数。此外,该声明应有效用于评估,即eval("2*x+5"…

如何在JQuery中操作JSONArray - javascript

我有一个php函数,它以JSON返回此代码{"0":{"title":"Dans l\u2019appartement"},"1":{"title":"A l\u2019a\u00e9roport - D\u00e9part de B\u00e9at…

在两个值之间匹配并返回正则表达式 - javascript

我正在尝试使用正则表达式从字符串中获取值,该值是tt="和"&之间的文本的值因此,例如,"tt="Value"&"我只想从中得到单词"Value"。到目前为止,我已经有了:/tt=.*&/这给了我"tt=Value"&,然后,要…