You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Acumatica中使用PXRedirectToUrlException打开两个URL标签页

Acumatica 实现多URL独立新标签页打开

原代码的问题在于,抛出第一个PXRedirectToUrlException后程序会直接终止,第二个异常语句根本不会执行,因此只能打开第一个URL的新标签页。要实现同时打开两个独立标签页,可通过注册客户端JavaScript脚本的方式实现:

修改后的代码示例

int countFirst = 3;
int countSecond = 4;
StringBuilder openTabsScript = new StringBuilder();

if (countFirst > 0)
{
    // 对URL进行JS转义,避免特殊字符导致脚本错误
    string safeFirstUrl = HttpUtility.JavaScriptStringEncode(firstUrl);
    openTabsScript.Append($"window.open('{safeFirstUrl}', '_blank');");
}

if (countSecond > 0)
{
    string safeSecondUrl = HttpUtility.JavaScriptStringEncode(secondUrl);
    openTabsScript.Append($"window.open('{safeSecondUrl}', '_blank');");
}

// 如果有需要打开的标签,注册客户端脚本
if (openTabsScript.Length > 0)
{
    PX.Web.UI.PXClientScriptManager.RegisterClientScriptBlock(
        this, 
        typeof(YourGraphClassName), // 替换为你的图类名称
        "OpenMultipleTabs", 
        openTabsScript.ToString(), 
        true
    );
}

说明

  1. 利用StringBuilder拼接需要执行的JavaScript代码,通过window.open方法分别打开每个URL,_blank参数确保在新标签页打开。
  2. 使用HttpUtility.JavaScriptStringEncode对URL进行转义,避免URL中的特殊字符破坏脚本结构,同时防范XSS风险。
  3. 通过PXClientScriptManager.RegisterClientScriptBlock将脚本注册到客户端,确保页面加载后执行脚本打开标签页。

内容的提问来源于stack exchange,提问作者Jeremy Valdez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 22:30:48