用于在自定义策略中移动 link 位置的 JS 代码在 azure b2c 中不起作用

JS code to move link location in custom policy doesn't work in azure b2c

我必须移动我忘记的密码 link,我在我的登录和注册自定义策略中使用了启用 javascript 的所有步骤,如 this documentation 中所述。

我的 JS 代码是(它在本地 html 页面而不是 azure 中工作):

<script type="text/javascript" data-preload="true">
window.onload = function moveLinks() {

        alert("Test!!");
        /* Password Link*/
        v_div = document.createElement("div");
        v_div.setAttribute("id","divPass");
        
        
        var passLink = document.getElementById("forgotPassword");
        
        v_div.appendChild(passLink);
        next.parentNode.insertBefore(v_div, next.nextSibling);
}
</script>

当我检查页面时,我在头部看到我的 js 代码,没有检测到错误,没有出现警告,我不明白错误从何而来!!

有人可以帮忙吗?

• 出现错误是因为您的语法无效,因为您似乎正在尝试将内联标记用作 javascript 元素,因为它会引发意外的标记错误,但标记的工作方式不同它们在 HTML 中的工作方式,因为它们仍然必须遵循 javascript 语法,因此它们不能包含任意 javascript 代码,因为您正在自定义策略代码中修改 B2C 页面布局。

因此,我建议您省略标记并执行以下操作。以下只是一个示例参考:-

  ‘ import {javascript} from ‘<name of the referencing HTML file>’;
   window.onload = function moveLinks() {

    alert("Test!!");
    /* Password Link*/
    v_div = document.createElement("div");
    v_div.setAttribute("id","divPass");
    
    
    var passLink = document.getElementById("forgotPassword");
    
    v_div.appendChild(passLink);
    next.parentNode.insertBefore(v_div, next.nextSibling);
   }
 export passLink;

因此,通过使用'import'参数,javascript代码可以成功修正。另外,请参考下面的 links 以更清楚地了解代码修改和编译:-

https://github.com/eslint/eslint/issues/10628

https://developer.salesforce.com/forums/?id=9062I000000IKXYQA4

此外,请参阅下面的 link 以了解有关自定义 B2C UI 的更多详细信息:-

https://moviesdiag132.blob.core.windows.net/b2c/global.css