【问题标题】:Toast Notification - Open a web page with specific character on the linkToast 通知 - 打开链接上带有特定字符的网页
【发布时间】:2021-11-27 16:27:16
【问题描述】:

我使用 Powershell 和 XML 创建了一个 toast 通知来显示一些信息,现在我想使用一个按钮将用户重定向到特定网页。
就是在网络链接上,有一个特定的字符为“=”,我总是得到一个错误。 我尝试使用变量,不同类型的引号,现在我有点卡住了。 我得到的错误是:

错误:“'=' 是一个意外的标记。预期的标记是 ';'。

还有代码:

[xml]$Toast = @"
<toast scenario="$Scenario">
    <visual>
    <binding template="ToastGeneric">
        <group>
            <subgroup>
                <text hint-style="title" hint-wrap="true" >$TitleText</text>
            </subgroup>
        </group>
        <group>
            <subgroup>
                <text hint-style="Body" hint-wrap="true" >$BodyText1</text>
            </subgroup>
        </group>
        <group>
            <subgroup>     
                <text hint-style="base" hint-wrap="true" >$BodyText2</text>
            </subgroup>
        </group>
        <group>
            <subgroup>     
                <text hint-style="body" hint-wrap="true" >$BodyText3</text>
            </subgroup>
        </group>
    </binding>
    </visual>
    <actions>        
        <action arguments="https://part_of_the_link.aspx?C_ECRAN=HELP5_REQ_SYS&Type=LINK&Action=A&FieldName=C_OBJETSERVICE&FieldValue=THING" content="Open Web Page" activationType="protocol" />
        <action activationType="system" arguments="dismiss" content="$DismissButtonContent"/>
    </actions>
</toast>
"@

【问题讨论】:

    标签: xml windows powershell notifications toast


    【解决方案1】:

    错误消息可能会让您失望,因为 URL 的问题实际上不是 =,而是您没有转义 param=value 对之前的文字 & 符号 (&amp;)字符串。

    在 PowerShell 中转义字符串的最简单方法可能是使用 [SecurityElement]::Escape():

    [xml]$Toast = @"
    <toast scenario="$Scenario">
        <visual>
        <binding template="ToastGeneric">
            <group>
                <subgroup>
                    <text hint-style="title" hint-wrap="true" >$TitleText</text>
                </subgroup>
            </group>
            <group>
                <subgroup>
                    <text hint-style="Body" hint-wrap="true" >$BodyText1</text>
                </subgroup>
            </group>
            <group>
                <subgroup>     
                    <text hint-style="base" hint-wrap="true" >$BodyText2</text>
                </subgroup>
            </group>
            <group>
                <subgroup>     
                    <text hint-style="body" hint-wrap="true" >$BodyText3</text>
                </subgroup>
            </group>
        </binding>
        </visual>
        <actions>        
            <action arguments="$([System.Security.SecurityElement]::Escape('https://part_of_the_link.aspx?C_ECRAN=HELP5_REQ_SYS&Type=LINK&Action=A&FieldName=C_OBJETSERVICE&FieldValue=THING'))" content="Open Web Page" activationType="protocol" />
            <action activationType="system" arguments="dismiss" content="$DismissButtonContent"/>
        </actions>
    </toast>
    "@
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多