zoukankan      html  css  js  c++  java
  • 防止重复提交的脚本。


    写的防止重复提交的脚本
    http://blog.joycode.com/lostinet/archive/2004/09/18/33901.aspx

    把这个作为 <-script src=.....js-><-/script-> 的形式Render到每个页面中就可以了。|
    如果有PageBase,则在Init的时候用RegisterClientScriptBlock放上去更好。
    因为客户没有抱怨过,所以也没有改进过。


    function _doPostBack(){};
    if(typeof("__doPostBack")=="function")
    {
        _doPostBack=__doPostBack;
        __doPostBack=_doPostBackNew;
    }

    document.attachEvent("onmousemove",_onmousemove);
    var _isPosting=false;
    var _divMask=null;

    function _onmousemove()
    {
        if(_divMask)
        with(_divMask.runtimeStyle)
        {
            left=event.clientX+document.body.scrollLeft-4;
            top=event.clientY+document.body.scrollTop-4;
        }
    }


    function _makeMask()
    {
        var div=document.createElement("DIV");
        with(div.runtimeStyle)
        {
            position="absolute";
            zIndex=999999;
            fontSize="1px";
            left=event.clientX+document.body.scrollLeft-4;
            top=event.clientY+document.body.scrollTop-4;
            width="8px";
            height="8px";
            cursor="wait";
           
            backgroundColor="gray";
            filter="alpha(opacity=10)";
        }
        try
        {
            document.body.insertAdjacentElement("BeforeEnd",div);
            div.onblur=new Function("this.focus()");
            div.focus();
        }
        catch(x){}
       
        if(_divMask)_divMask.removeNode(true);
        _divMask=div;
    }

    function _doPostBackNew(sender,args)
    {
        if(_isPosting)
            return event.returnValue=!(event.cancelBubble=true);

        status="正在更新页面...";
        _doPostBack(sender,args);       
        _isPosting=true;
        _makeMask();
    }

    function _onformsubmit()
    {
        if(_isPosting)
            return event.returnValue=!(event.cancelBubble=true);

        _isPosting=true;
        _makeMask();
    }
    new function _attachForms()
    {
        with(new Enumerator(document.forms))
        for(;!atEnd();moveNext())
        {
            item().attachEvent("onsubmit",_onformsubmit);
            var div=document.createElement("div");
            div.runtimeStyle.width="0px";
            div.runtimeStyle.hight="0px";
            div.runtimeStyle.overflow="hidden";
            div.runtimeStyle.position="absolute";
            item(0).insertAdjacentElement("afterbegin",div);
            div.innerHTML="<INPUT TYPE=Submit name='webformpatchsubmitelement' onclick='return event.returnValue=false' id='webformpatchsubmitelement' value='webformpatchsubmitelement'/>";
        }
    }

  • 相关阅读:
    redis 设置分布式锁要避免死锁
    jmeter的简单http接口用法
    整理一些好的网站或者好的文章来慢慢学
    多线程的共享变量的内存不可见性如何理解
    谷歌浏览器可以google了
    org.apache.commons.dbcp.DelegatingPreparedStatement.isClosed()Z和NewProxyPreparedStatement.isClosed()
    php封装curl,模拟POST和GET请求HTTPS请求
    PHP 轻量级 REST框架
    使用 spring封装的javamail linux服务器发送邮件失败解决
    安装Ruby、Sass在WebStrom配置Scss编译环境css自动压缩
  • 原文地址:https://www.cnblogs.com/huqingyu/p/213078.html
Copyright © 2011-2022 走看看