JavaScript 之 日常积累

1. <a>标签"加入收藏",兼容IE,FireFox等

function bookmarksite() {

            if (window.sidebar) { 

                // Mozilla Firefox Bookmark

                window.sidebar.addPanel(document.title, window.location.href, '');

            }

            else if (window.external && ('AddFavorite' in window.external)) { 

                // IE Favorite

                window.external.AddFavorite(location.href, document.title);

            } else if (window.opera && window.print) { 

                // Opera Hotlist

                this.title = document.title;

                return true;

            } else { 

                // webkit - safari/chrome

                alert('Press ' + (navigator.userAgent.toLowerCase().indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL') + ' + D to bookmark this page.');

            }

        }

        //加入收藏

        function bookmarksite(title, url) {

            if (window.sidebar) // firefox

                window.sidebar.addPanel(title, url, "");

            else

                if (window.opera && window.print) { // opera

                    var elem = document.createElement('a');

                    elem.setAttribute('href', url);

                    elem.setAttribute('title', title);

                    elem.setAttribute('rel', 'sidebar');

                    elem.click();

                }

                else

                    if (document.all)// ie

                        window.external.AddFavorite(url, title);

            }
View Code

2、刷新页面避免重新发送

//用下面替换 document.location.reload();

location.href = location.href; 

若为cs后台:在执行的方法尾部添加一条重载页面既可。

Response.Redirect(Request.Url.ToString());

 

你可能感兴趣的:(JavaScript)