繁体   English   中英

在asp.net中向用户发送通知

[英]send notifications to user in asp.net

我尝试在asp.net中发送通知

当管理员登录并单击添加消息时,此消息会在用户登录时发送给用户,然后出现弹出通知

在这里我尝试

<input class="add_message" type="text" value="type your message" name="add_message">
</input>
 <input type="button" value="add message" 
    önclick="sNotify.addToQueue($(".add_message").attr("value"))"></input>

   <script type='text/javascript'>
   sNotify.addToQueue("You can add your message here."); 

   sNotify.timeOpen = 10;

这段代码在try.appx中尝试

这是我得到概念..plz的链接,我实现了该链接,并在js文件夹中添加了javascript并尝试对其进行编码,但是当我单击添加消息时,弹出无法显示...? 我该怎么做? 链接

有什么帮助吗?

头段代码

<link href='css/sNotify.css' rel='stylesheet' type='text/css' />
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js'></script>
<script src="js/sNotify.js" type="text/javascript"></script>

这是CSS

 body {
    width: 100%;
    overflow: hidden;   
}

.sNotify_message {
    width: 250px;
    padding: 20px;
    background-color: white;
    position: absolute;
    display: none;
    right: 0px;
    top: 20px;
    margin-bottom: 20px;
    text-align: justify;
    border: 1px solid #808080;
}

.sNotify_close {
    display: block;
    background-color: black;
    padding: 3px;
    position: absolute;
    top: -5px;
    right: -5px;
    color: white;
    font-weight: bold;
    width: 10px;
    height: 10px;
    cursor: pointer;
    text-align: center;
    line-height: 10px;
}

这是js

var sNotify = {

    timeOpen: 10,   //change this number to the amount of second you want the message opened

    queue: new Array(),
    closeQueue: new Array(),

    addToQueue: function(msg) {
        sNotify.queue.push(msg);
    },

    createMessage: function(msg) {

        //create HTML + set CSS
        var messageBox = $("<div><span class=\"sNotify_close\">x</span>" + msg + "</div>").prependTo("body");
        $(messageBox).addClass("sNotify_message");

        sNotify.enableActions(messageBox);
        sNotify.closeQueue.push(0);

        return $(messageBox);

    },

    loopQueue: function() {
        //pop queue
        if (sNotify.queue.length > 0) {

            var messageBox = sNotify.createMessage(sNotify.queue[0]);
            sNotify.popMessage(messageBox);

            sNotify.queue.splice(0,1);

        }

        //close queue
        if (sNotify.closeQueue.length > 0) {
            var indexes = new Array();

            for (var i = 0; i < sNotify.closeQueue.length; i++) {
                sNotify.closeQueue[i]++;

                if (sNotify.closeQueue[i] > sNotify.timeOpen) {
                    indexes.push(i);
                }
            }

            //now close them
            for (var i = 0; i < indexes.length; i++) {
                var buttons = $(".sNotify_close");
                sNotify.closeMessage($(buttons[($(buttons).length - indexes[i]) - 1]));
                sNotify.closeQueue.splice(indexes[i],1);    
            }

        }

    },

    enableActions: function(messageBox) {
        //reset timer when hovering
        $(messageBox).hover(
            function() {
                var index = ($(this).nextAll().length - 1);
                sNotify.closeQueue[index] = -1000;
            },
            function() {
                var index = ($(this).nextAll().length - 1);
                sNotify.closeQueue[index] = 0;
            }
        );

        //enable click close button
        $(messageBox).find(".sNotify_close").click(function() {
            sNotify.closeMessage(this);
        });
    },

    popMessage: function(messageBox) {
        $(messageBox).css({
            marginRight: "-290px",
            opacity: 0.2,
            display: "block"
        });

        var height = parseInt($(messageBox).outerHeight()) + parseInt($(messageBox).css("margin-bottom"));

        $(".sNotify_message").next().each(function() {
            var topThis = $(this).css("top");

            if (topThis == "auto") {
                topThis = 0;
            }

            var newTop = parseInt(topThis) + parseInt(height);

            $(this).animate({
                top: newTop + "px"
            }, {
                queue: false,
                duration: 600
            });
        });

        $(messageBox).animate({
            marginRight: "20px",
            opacity: 1.0
        }, 800);
    },

    closeMessage: function(button) {
        var height = parseInt($(button).parent().outerHeight()) + parseInt($(button).parent().css("margin-bottom"));

        $(button).parent().nextAll().each(function() {
            var topThis = $(this).css("top");

            if (topThis == "auto") {
                topThis = 0;
            }

            var newTop = parseInt(topThis) - parseInt(height);

            $(this).animate({
                top: newTop + "px"
            }, {
                queue: false,
                duration: 300
            });
        });

        $(button).parent().hide(200, function() {
            $(this).remove();
        });
    }

}

setInterval("sNotify.loopQueue()", 900);

这是按钮点击代码

<input class="add_message" type="text" value="type your message" name="add_message"></input>

<input type="button" value="add message" onclick="sNotify.addToQueue($(".add_message").attr("value"))"></input>

假设有两种形式abc.aspx和def.aspx形式,并且我在abc.aspx中完成了代码,并且可以正常工作,在这里,当管理员按下按钮时,弹出窗口出现在abc.aspx页面中,但是我想要在这里,当管理员按下按钮时,通知发送到def.aspx表单即用户表单。

抱歉,这应该是评论,但没有足够的代表

我注意到的第一件事是onclick作为ö而不是o-可能就这么简单,但正如susai所说-更多代码会有所帮助!

您已在管理页面中使用了sNotify插件(例如abc.aspx)。 如您所说,您没有在用户页面中实现该功能(例如def.aspx)。 sNotify插件不会在未实现的地方自动将通知填充到其他页面。

为了实现您的目标,请将所有通知保存在管理页面中。 在用户页面中实现sNotify插件。 使用服务器推或拉技术读取已保存的通知,并将它们添加到sNotify队列中,以便在管理员执行操作时通知将显示在用户页面中。

暂无
暂无

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

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