gpt4 book ai didi

javascript - ADF 中的浏览器事件关闭

转载 作者:太空宇宙 更新时间:2023-11-04 10:25:15 24 4
gpt4 key购买 nike

我有 JSF 页面,我想在用户尝试关闭时检测浏览器事件关闭

选项卡或所有浏览器都会阻止他,如果他想离开此页面或留下来 我需要在后端调用java方法java脚本 我尝试这样做,但页面上的服务器监听器看不到来自 js 的操作 所以我需要帮助才能取得成功

window.onbeforeunload = function (event) {
console.log(" Test Event Console .")
var docComponent = AdfPage.PAGE.findComponentByAbsoluteId('d1');

console.log(" value component = " + docComponent);

var dialogText = ' browser Is Closed !.. ';
console.log(dialogText);

var x = AdfCustomEvent.queue(docComponent, "test",{"test":"so"},false);
console.log("test " + x);
var y = 0;


event.returnValue = dialogText;

return x;
};


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html>
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<af:document title="testBrowserChrome.jsf" id="d1" clientComponent="true" onunload="onbeforeunload">
<af:form id="f1">
<af:resource type="javascript" source="resources/js/BrowserEventClose.js"/>
<af:serverListener type="test" method="#{viewScope.ServerTest.testServerListener}"/>
</af:form>
</af:document>

</f:view>

最佳答案

我建议您创建一个具有该操作的按钮,并使用以下代码模拟按钮触发器,因为 theButton 是该按钮的 ID。

var adfButton = AdfPage.PAGE.findComponentByAbsoluteId("theButton");
AdfActionEvent.queue(adfButton , true /*Immediate*/);

关于javascript - ADF 中的浏览器事件关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50620281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com