javascript - 当asp.net页面有特定查询字符串时调用JQuery函数

标签 javascript c# jquery asp.net

我有 JQuery 函数显示通知消息。 从我的 asp.net 页面,我想在页面完全加载时调用它,例如:Request.QueryString[c_opID] != null; 我尝试使用 ScriptManager.RegisterStartupScript() 从 Page_Load 和 Page_LoadComplete 调用该函数,但该函数没有启动。另一方面,当我在按钮上调用它时,单击它会执行应该执行的操作。

JQuery 函数:

function showMessage(title, message) {
    PNotify.prototype.options.styling = "jqueryui";
    var notice = new PNotify({
        title: title,
        text: message,
        type: 'success',
        opacity: 1,
        animate_speed: 'fast',
        addclass: 'custom'
    });
    notice.get().click(function() {
        notice.remove();
    });
    setTimeout(function() {
        notice.remove();
    }, 3000);
}

调用背后的Asp.Net代码:

            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", @"showMessage('" + title + "','" + message + "');", true);

最佳答案

替代方案是纯js

您所需要的只是使用 javascript 从 url 获取参数。这是一种解决方案(复制自 How can I get query string values in JavaScript? )

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

然后

$(function () {

    if (getParameterByName('your_parameter_name')){
        // show message
    }
})

关于javascript - 当asp.net页面有特定查询字符串时调用JQuery函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27165468/

相关文章:

javascript - 如何在函数中返回 Ajax 的值?

c# - 全局异常过滤器或 Application_Error 都没有捕获未处理的异常

c# - 如何阻止 linqpad 显示写入 Debug.Writeline 的语句的输出?

javascript - 单击元素外部的代码未触发

jQuery,使下拉菜单在单击其他地方时隐藏

javascript - 如何编写搜索数组的循环

javascript - Puppeteer:如何在嵌套选择器中获取 img src?

javascript - 适合 View 并在 Google map 上显示用户位置以及所有其他标记

javascript - 尾随 "="在 angular2 url 中被 trim

c# - Form.ShowInTaskBar/Process.MainWindowHandle