简体   繁体   English

如何在页面加载和自动点击时获取警报消息内容

[英]how to get alert message content when page load and auto click

i have sevrale pages that have multiple jquery datatable and i just want to auto click alert when alert have this message: 'DataTables warning: table id=' .我有多个具有多个 jquery 数据表的页面,我只想在警报出现此消息时自动单击警报: 'DataTables warning: table id=' i have set this javascript for auto click if this message comes.如果出现此消息,我已将此 javascript 设置为自动单击。

code:代码:

<script type="text/javascript">
        debugger;
        var htmlString = new XMLSerializer().serializeToString(document)
        var indexOfAlertBeginning = "";
        var indexOfAlertEnd = "";
        var stringFromAlert = "";
        var alertMessages = "";
        if (htmlString.includes('alert(')) {
            indexOfAlertBeginning = htmlstring.indexof('alert(');
            stringFromAlert = htmlstring.substr(indexOfAlertBeginning);
            indexOfAlertEnd = stringFromAlert.indexof(')');
            alertMessages = stringFromAlert(0, indexOfAlertEnd);
        }
        if (stringFromAlert.includes('DataTables warning: table id=', 0)) {
            window.alert = function () {
                return true;
            }
        }
    </script>

but this have no effect and alert message comes up every time.但这没有效果,并且每次都会出现警报消息。 whats' wrong here please help me...这里有什么问题请帮助我...

If you are loading data to the table using ajax most of the time cause the problem unmatched column name between json data and columnname in your script.如果您在大多数情况下使用 ajax 将数据加载到表中,则会导致脚本中 json 数据和列名之间列名不匹配的问题。 I found this post pretty useful for datatable and.Net Jquery Datatable with.Net我发现这篇文章对数据表和.Net Jquery Datatable with.Net非常有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM