(转)Firefox中Iframe的blur与focus事件问题

最近在做一个网站的HTML文章发布功能,用到了HTML编辑器,这个是以Iframe为基础的编辑器(貌似网上大多的都是用iframe 的)。却发现一个问题,IE下运行得好好的,在Firefox里却始终不能提交更新后的数据到服务器上,找了半天原因才发现原来是在iframe的 onblur事件里面调了更新数据内容的方法,但firefox下却没有执行。GOOGLE,发现了一个老外写的如下代码:

<script>
	function setit(){
		if(document.all){
			document.getElementById("myframe").attachEvent("onblur",dothis);
		}else{
			document.getElementById("myframe").contentWindow.addEventListener("blur",dothis,false);
		}
	}

	function dothis(){
		alert("blurred");
	}
</script>

<body onload="setit()">
	<iframe width="155" height="144" id="myframe"></iframe>
	<input />
</body>

试了一下果真可以直接触发,效果跟在IE下的一样。回过头去分析了一下代码,发现firefox中原来iframe上的事件挂到了iframe中的 contentWindow中去了,与真接在html元素里面写事件属性相比,IE可能把iframe上的事件关联到了contentWindow上了, 可firefox却不是这样的,还是各是各的。这样带来的问题是firefox想要给iframe加事件只能够用脚本去加了。
本来以为IE和firefox中对iframe的事件这部分定义不一样,回头去再去看看了HTML4.0中关于iframe的定义,果真是 iframe上面就没有任何事件的定义,看来是IE顺手给加上的。firefox号称最符合html标准,那么写在iframe上的“事件”没有任何响 应,自然也是合情合理的。DHTML手册上有一句话,由于没有“window”元素,body 元素将作为下列 window 对象事件的宿主:onblur, onbeforeunload, onfocus, onload 和 onunload。可HTML4.0里面body是有这两个事件的,所以也就不难解释为什么用脚本给iframe的contentWindow挂上事件就可以触发了,实际上这个事件是来自于contentWindow里面的body元素。

Ajax操作中维持历史记录

进行了一个ajax操作后,如何才能在浏览器的历史记录里显示呢,IE里可以通过放一个隐藏的iframe,改变iframe的location或者dom内容即可在history里面显示记录,firefox中就比较简单了,只需改变页面地址就可以产生一条历史记录,如在url后面加#XXX,

轻松去掉flash中的右键菜单

在flash父容器里hack:firefox下阻止mousedown默认事件及事件传播;IE下给父容器setCapture。JavaScript脚本如下:

function NoRightClick(pid){//pid:flash's parentNode id  说明:flash父容器的id
 
var el = document.getElementById(pid);
 
if(el.addEventListener){
 
el.addEventListener("mousedown",function(event){
  
if(event.button == 2){
    
event.stopPropagation(); //for firefox
    
event.preventDefault()//for chrome
  
}
 
},true);
 
}else{
 
el.attachEvent("onmousedown",function(){
  
if(event.button == 2){
    
el.setCapture();
  
}
 
});
 
el.attachEvent("onmouseup",function(){
  
el.releaseCapture();
 
});
 
el.oncontextmenu = function(){
  
return false;
 
};
 
}
};
 
html页面中的代码如下:
<body>
 
<div id="testContent" style="width:800px">
 
</div>
 
<script type="text/javascript">
  var so = new SWFObject("test.swf", "t1", "800", "550", "9", "#000000");
  so.addParam("quality", "high");
  so.addParam("name", "t1");
  so.addParam("id", "t1");
  so.addParam("algin", "middle");
  so.addParam("AllowScriptAccess", "sameDomain");
  so.addParam("menu", "false");
  so.addParam("wmode", "opaque");
  so.addParam("pluginspage", "http://www.adobe.com/go/getflashplayer");
  so.write("testContent");
 
  NoRightClick("testContent");
 
</script>
</body>

 

Javascript格式化工具,压缩工具

<SCRIPT language=JavaScript>

function CLASS_FORMAT(code){

    function Hashtable(){
        this._hash        = new Object();
        this.add        = function(key,value){
                            if(typeof(key)!="undefined"){
                                if(this.contains(key)==false){
                                    this._hash[key]=typeof(value)=="undefined"?null:value;
                                    return true;
                                } else {
                                    return false;
                                }
                            } else {
                                return false;
                            }
                        }
        this.remove        = function(key){delete this._hash[key];}
        this.count        = function(){var i=0;for(var k in this._hash){i++;} return i;}
        this.items        = function(key){return this._hash[key];}
        this.contains    = function(key){return typeof(this._hash[key])!="undefined";}
        this.clear        = function(){for(var k in this._hash){delete this._hash[k];}}

    }

    this._caseSensitive = true;

    this.str2hashtable = function(key,cs){

        var _key    = key.split(/,/g);
        var _hash    = new Hashtable();
        var _cs        = true;

        if(typeof(cs)=="undefined"||cs==null){
            _cs = this._caseSensitive;
        } else {
            _cs = cs;
        }

        for(var i in _key){
            if(_cs){
                _hash.add(_key[i]);
            } else {
                _hash.add((_key[i]+"").toLowerCase());
            }

        }
        return _hash;
    }

    this._codetxt        = code;

    if(typeof(syntax)=="undefined"){
        syntax = "";
    }

    this._deleteComment = false;

    this._caseSensitive = true;

    this._blockElement  = this.str2hashtable("switch,if,do,while,try,finally");

    this._function      = this.str2hashtable("function");

    this._isFor            = "for";

    this._choiceElement = this.str2hashtable("else,catch,while");

    this._beginBlock    = "{";
    this._endBlock      = "}";

    this._singleEyeElement = this.str2hashtable("var,new,return,else,delete,in,case,typeof");

    this._wordDelimiters= "  ,.?!;:\\/<>(){}[]\"'\r\n\t=+-|*%@#$^&";

    this._quotation     = this.str2hashtable("\",'");

    this._lineComment   = "//";

    this._escape        = "\\";

    this._commentOn        = "/*";

    this._commentOff    = "*/";

    this._rowEnd        = ";";
    this._in            = "in";

    this.isCompress     = false;
    this.style          = 0;
    this._tabNum        = 0;

    this.format = function() {
        var codeArr        = new Array();
        var word_index    = 0;
        var htmlTxt        = new Array();

        if(this.isCompress){
            this._deleteComment = true;
        }

        for (var i = 0; i < this._codetxt.length; i++) {
            if (this._wordDelimiters.indexOf(this._codetxt.charAt(i)) == -1) {
                if (codeArr[word_index] == null || typeof(codeArr[word_index]) == 'undefined') {
                    codeArr[word_index] = "";
                }
                codeArr[word_index] += this._codetxt.charAt(i);
            } else {
                if (typeof(codeArr[word_index]) != 'undefined' && codeArr[word_index].length > 0)
                    word_index++;
                codeArr[word_index++] = this._codetxt.charAt(i);
            }
        }

        var quote_opened                = false;
        var slash_star_comment_opened   = false;
        var slash_slash_comment_opened  = false;
        var line_num                    = 1;
        var quote_char                  = "";      

        var function_opened             = false;

        var bracket_open                = false;
        var for_open                    = false;

        for (var i=0; i <=word_index; i++){
            if(typeof(codeArr[i])=="undefined"||codeArr[i].length==0){
                continue;
            } else if(codeArr[i]==" "||codeArr[i]=="\t"){
                if(slash_slash_comment_opened||slash_star_comment_opened){
                    if(!this._deleteComment){
                        htmlTxt[htmlTxt.length] = codeArr[i];
                    }
                }
                if(quote_opened){
                        htmlTxt[htmlTxt.length] = codeArr[i];
                }
            } else if(codeArr[i]=="\n"){
            } else if (codeArr[i] == "\r"){
                slash_slash_comment_opened = false;
                quote_opened    = false;
                line_num++;
                if(!this.isCompress){
                    htmlTxt[htmlTxt.length] = "\r\n"+ this.getIdent();
                }
            } else if (!slash_slash_comment_opened&&!slash_star_comment_opened && !quote_opened &&this.isFunction(codeArr[i])){
                htmlTxt[htmlTxt.length] = codeArr[i]  + " ";
                function_opened = true;
            } else if (!slash_slash_comment_opened&&!slash_star_comment_opened && !quote_opened &&codeArr[i]==this._isFor){
                htmlTxt[htmlTxt.length] = codeArr[i];
                for_open = true;
            } else if (!slash_slash_comment_opened&&!slash_star_comment_opened && !quote_opened &&codeArr[i]=="("){
                bracket_open    = true;
                htmlTxt[htmlTxt.length] = codeArr[i];
            } else if (!slash_slash_comment_opened&&!slash_star_comment_opened && !quote_opened &&codeArr[i]==")"){
                bracket_open    = false;
                htmlTxt[htmlTxt.length] = codeArr[i];
            } else if (!slash_slash_comment_opened&&!slash_star_comment_opened && !quote_opened &&codeArr[i]==this._rowEnd){
                if(!this.isCompress){
                    if(!for_open){
                        if(i<word_index&&(codeArr[i+1]!="\r"&&codeArr[i+1]!="\n")){
                            htmlTxt[htmlTxt.length] = codeArr[i] + "\n" + this.getIdent();
                        }else{
                            htmlTxt[htmlTxt.length] = codeArr[i] + this.getIdent();
                        }
                    }else{
                        htmlTxt[htmlTxt.length] = codeArr[i];
                    }
                }else{
                    htmlTxt[htmlTxt.length] = codeArr[i];
                }
            } else if(!slash_slash_comment_opened&&!slash_star_comment_opened && !quote_opened &&codeArr[i]==this._beginBlock){
                for_open    = false;
                if(!this.isCompress){
                    switch(this.style){
                        case 0:
                            this._tabNum++;
                            htmlTxt[htmlTxt.length] = codeArr[i] + "\n" + this.getIdent();
                            break;
                        case 1:
                            htmlTxt[htmlTxt.length] = "\n" + this.getIdent();
                            this._tabNum++;
                            htmlTxt[htmlTxt.length] = codeArr[i] + "\n"+ this.getIdent();
                            break;
                        default:
                            this._tabNum++;
                            htmlTxt[htmlTxt.length] = codeArr[i];
                            break;

                    }
                }else{
                    htmlTxt[htmlTxt.length] = codeArr[i];
                }

            } else if(!slash_slash_comment_opened&&!slash_star_comment_opened && !quote_opened &&codeArr[i]==this._endBlock){
                if(!this.isCompress){
                    this._tabNum--;
                    htmlTxt[htmlTxt.length] = "\n" + this.getIdent() + codeArr[i];
                }else{
                    if(i<word_index&&this.isNextChar(i,codeArr)==false){
                        htmlTxt[htmlTxt.length] = codeArr[i] + this._rowEnd;
                    }else{
                        htmlTxt[htmlTxt.length] = codeArr[i];
                    }
                }
            } else if (!slash_slash_comment_opened&&!slash_star_comment_opened && !quote_opened && this.isBlockElement(codeArr[i])){
                htmlTxt[htmlTxt.length] = codeArr[i];
            } else if (!slash_slash_comment_opened&&!slash_star_comment_opened && !quote_opened && this.isSingleEyeElement(codeArr[i])){
                if(codeArr[i]==this._in){
                    htmlTxt[htmlTxt.length] = " ";
                }
                htmlTxt[htmlTxt.length] = codeArr[i] + " ";
            } else if (!slash_star_comment_opened&&!slash_slash_comment_opened&&this._quotation.contains(codeArr[i])){
                if (quote_opened){
                    if(quote_char==codeArr[i]){
                        htmlTxt[htmlTxt.length] = codeArr[i];
                        quote_opened    = false;
                        quote_char      = "";
                    } else {
                        htmlTxt[htmlTxt.length] = codeArr[i];
                    }
                } else {
                    htmlTxt[htmlTxt.length] =  codeArr[i];
                    quote_opened    = true;
                    quote_char        = codeArr[i];
                }
            } else if(!slash_star_comment_opened&&!slash_slash_comment_opened &&codeArr[i] == this._escape){
                htmlTxt[htmlTxt.length] = codeArr[i];
                if(i<word_index-1){
                    if(codeArr[i+1].charCodeAt(0)>=32&&codeArr[i+1].charCodeAt(0)<=127){
                        htmlTxt[htmlTxt.length] = codeArr[i+1].substr(0,1);
                        htmlTxt[htmlTxt.length] = codeArr[i+1].substr(1);
                        i=i+1;
                    }
                }
            } else if (!slash_slash_comment_opened && !slash_star_comment_opened&&!quote_opened&&this.isStartWith(this._commentOn,codeArr,i)){
                slash_star_comment_opened = true;
                if(!this._deleteComment){
                    htmlTxt[htmlTxt.length] = this._commentOn;
                }
                i = i + this.getSkipLength(this._commentOn);
            } else if (!slash_slash_comment_opened && !slash_star_comment_opened&&!quote_opened&&this.isStartWith(this._lineComment,codeArr,i)){
                slash_slash_comment_opened = true;
                if(!this._deleteComment){
                    htmlTxt[htmlTxt.length] =  this._lineComment;
                }
                i = i + this.getSkipLength(this._lineComment);
            } else if (!slash_slash_comment_opened && !slash_star_comment_opened&&!quote_opened&&this.isStartWith(this._ignore,codeArr,i)){
                slash_slash_comment_opened = true;
                htmlTxt[htmlTxt.length] = this._ignore;
                i = i + this.getSkipLength(this._ignore);
            } else if (!quote_opened&&!slash_slash_comment_opened&&this.isStartWith(this._commentOff,codeArr,i)){
                if (slash_star_comment_opened) {
                    slash_star_comment_opened = false;
                    if(!this._deleteComment){
                        htmlTxt[htmlTxt.length] =  this._commentOff;
                    }
                    i = i + this.getSkipLength(this._commentOff);
                }
            } else {
                if(!quote_opened){
                    if(!slash_slash_comment_opened && !slash_star_comment_opened){
                            htmlTxt[htmlTxt.length] = codeArr[i];
                    }else{
                        if(!this._deleteComment){
                            htmlTxt[htmlTxt.length] = codeArr[i];
                        }
                    }
                }else{
                            htmlTxt[htmlTxt.length] = codeArr[i];
                }
            }

        }

        return htmlTxt.join("");
    }

    this.isStartWith = function(str,code,index){

        if(typeof(str)!="undefined"&&str.length>0){
            var cc = new Array();
            for(var i=index;i<index+str.length;i++){
                cc[cc.length] = code[i];
            }
            var c = cc.join("");
            if(this._caseSensitive){
                if(str.length>=code[index].length&&c.indexOf(str)==0){
                    return true;
                }
            }else{
                if(str.length>=code[index].length&&c.toLowerCase().indexOf(str.toLowerCase())==0){
                    return true;
                }
            }
            return false;

        } else {
            return false;
        }
    }

    this.isFunction = function(val){
        return this._function.contains(this._caseSensitive?val:val.toLowerCase());
    }

    this.isBlockElement = function(val) {
        return this._blockElement.contains(this._caseSensitive?val:val.toLowerCase());
    }

    this.isChoiceElement = function(val) {
        return this._choiceElement.contains(this._caseSensitive?val:val.toLowerCase());
    }

    this.isSingleEyeElement = function(val) {
        return this._singleEyeElement.contains(this._caseSensitive?val:val.toLowerCase());
    }

    this.isNextElement = function(from,word){
        for(var i=from+1;i<word.length;i++){
            if(word[i]!=" "&&word[i]!="\t"&&word[i]!="\r"&&word[i]!="\n"){
                return this.isChoiceElement(word[i]);
            }
        }
        return false;
    }

    this.isNextChar = function(from,word){
        for(var i=from+1;i<word.length;i++){
            if(word[i]!=" "&&word[i]!="\t"&&word[i]!="\r"&&word[i]!="\n"){
                return ";,)]}".indexOf(word[i])>=0||this.isChoiceElement(word[i]);
            }
        }
        return false;
    }

    this.getSkipLength = function(val){
        var count = 0;
        for(var i=0;i<val.length;i++){
            if(this._wordDelimiters.indexOf(val.charAt(i))>=0){
                count++;
            }
        }
        if(count>0){
            count=count-1;
        }
        return count;
    }

    this.getIdent=function(){
        var n = [];
        for(var i=0;i<this._tabNum;i++){
            n[n.length] = "\t";
        }
        return n.join("");
    }
}

function doformat(o){
    var htmltxt = "";

    if (o == null){
        alert("domNode is null!");
        return;
    }

    var _codetxt = "";

    if(typeof(o)=="object"){
        switch(o.tagName){
            case "TEXTAREA":
            case "INPUT":
                _codetxt = o.value;
                break;
            case "DIV":
            case "SPAN":
                _codetxt = o.innerText;
                break;
            default:
                _codetxt = o.innerHTML;
                break;
        }
    }else{
        _codetxt = o;
    }

    var _syn = new CLASS_FORMAT(_codetxt);
    htmltxt = _syn.format();
    return  htmltxt;
}

function go()
{
    var code    = document.getElementById("code").value;
    var xx      = new CLASS_FORMAT(code);
    var a       = new Date();

    if(document.getElementById('cboOperate').selectedIndex==1){
        xx.isCompress=true;
    }else{
        xx.style = parseInt(document.getElementById('cboStyle').value);
    }
    document.getElementById("display").value = xx.format();
    alert("共花:" + (new Date().getTime()-a.getTime()) + "ms");
}

</SCRIPT>
<TEXTAREA id=code rows=12 cols=100>
/*
这个是一个类
*/

function    xx   (num,str){//说明
var a = num;this.aa = a;
this.bb = function(){alert(str);}
this.cc = function(){for(var i=0;i<10;i++){document.title=i;}}//str=str.replace(/(\\)/gi,'\\\\');
};

var o = {a:function(){},b:345}

xx.prototype.dd= function(){alert("d  d        kd");}

var a = new xx(100,"hello"),b=new xx(0,"ttyp");
if(1>2)  {   alert();
 }
 else {
 alert(" hell ");
 }

a.bb();
b.dd();
alert(a.aa);

</TEXTAREA> <BR>
<select id="cboOperate" onchange="if(this.selectedIndex==1)document.getElementById('cboStyle').disabled=true;else document.getElementById('cboStyle').disabled=false;">
    <option value="0">格式化</option>
    <option value="1">压缩</option>
</select>
<select id="cboStyle">
    <option value="0">经典</option>
    <option value="1">微软</option>
</select>
<INPUT onclick=go() type=button value=go><br>
<textarea id=display rows=12 cols=100>
</textarea>

CSS代码格式化和css在线压缩工具

<script language="JavaScript">
function $()
{
	var elements=new Array();
	for(var i=0;i<arguments.length;i++)
	{
		var element=arguments[i];
		if(typeof element=='string')element=document.getElementById(element);
		if(arguments.length==1)return element;
		elements.push(element);
	}
	return elements;
}

function CSSencode(code)
{
	code=code.replace(/\n/ig,'');
	code=code.replace(/(\s){2,}/ig,'$1');
	code=code.replace(/\t/ig,'');
	code=code.replace(/\n\}/ig,'\}');
	code=code.replace(/\n\{\s/ig,'\{');
	code=code.replace(/(\S)\s*\}/ig,'$1\}');
	code=code.replace(/(\S)\s*\{/ig,'$1\{');
	code=code.replace(/\{\s*(\S)/ig,'\{$1');
	return code;
}

function CSSdecode(code)
{
	code=code.replace(/(\s){2,}/ig,'$1');
	code=code.replace(/(\S)\s*\{/ig,'$1 {');
	code=code.replace(/\*\/(.[^\}\{]*)}/ig,'\*\/\n$1}');
	code=code.replace(/\/\*/ig,'\n\/\*');
	code=code.replace(/;\s*(\S)/ig,';\n\t$1');
	code=code.replace(/\}\s*(\S)/ig,'\}\n$1');
	code=code.replace(/\n\s*\}/ig,'\n\}');
	code=code.replace(/\{\s*(\S)/ig,'\{\n\t$1');
	code=code.replace(/(\S)\s*\*\//ig,'$1\*\/');
	code=code.replace(/\*\/\s*([^\}\{]\S)/ig,'\*\/\n\t$1');
	code=code.replace(/(\S)\}/ig,'$1\n\}');
	code=code.replace(/(\n){2,}/ig,'\n');
	code=code.replace(/:/ig,': ');
	code=code.replace(/  /ig,' ');
	return code;
}
</script>
CSS代码格式化和css在线压缩/*请将CSS代码复制到下面*/<br/><br/>
<textarea id="code" style="width: 100%; height: 300px">
.rss_a:link{color:#99ccff;}
.rss_a:visited{color:#99ccff;}
.rss_a:hover{
	background-color:#e8f3fd;
	text-decoration:none;
	color:#008ed2;
	border:1pxsolid#99ccff;
}
</textarea>
<br />
<input type="button" onClick="$('code').value = CSSdecode($('code').value);" value="格式化" /> |
<input type="button" onClick="$('code').value = CSSencode($('code').value);" value="压缩化" /> |
<input type="button" onClick="window.clipboardData.setData('Text',$('code').value);" value="复制" /> |
<input type="button" onClick="$('code').value = window.clipboardData.getData('Text');" value="粘贴" /> |
<input type="button" onClick="$('code').value = ''" value="清空" />

[转帖]【个人实战,图文】-xp,vista 32位系统完美使用4G内存

【个人实战,图文】-xp,vista 32位系统完美使用4G内存目前微软旗下的所有32位操作系统均不能完全识别4GB容量的内存,无论是Windows XP、Windows 2003还是最新的Windows Vista,这些32位的操作系统都只能够识别2.75GB-3.25GB之间的内存。
现在内存很便宜,很多朋友在购买机器的时候直接将内存升级为4G。
那怎么样使系统无法使用的1G内存发挥作用呢?
答案就是:
使用一些工具,将那1G内存虚拟为一块硬盘,然后可以把系统的临时文件和IE的临时文件放进去。因为那块硬盘实际上还是在内存里,所以读写速度那是相当的快,而且也不会在硬盘上留下垃圾文件,更不会带来很多的磁盘碎片。

这么好的东西,需要什么软件来实现呢?我使用的是RamDisk,从名字就能看出来,这是一个把内存虚拟为硬盘的软件了。

在网上有很多版本的RamDisk下载,我试过一些,有的可以把未使用的内存虚拟为硬盘,而有的只能在使用的内存中划分一块作为硬盘,我们自然希望达到前者的效果。经过反复试验,终于找到了一个能正常工作的RamDisk,在下面的附件里。

如何来使用RamDisk虚拟硬盘呢,请看下文:

首先,需要下载下来RamDisk,然后解压缩

第二,按Ctrl alt delete ,看看现在的内存使用状况,这样方便一会判断是不是使用的高位内存虚拟为硬盘。
如下图,我的系统的可用内存数大约在1.9G

RamDisk1.png (47.59 KB)
2008-8-28 09:49

第三步,vista用户需要在命令行执行以下代码,xp用户跳过
在菜单栏,附件里找到命令提示符,单击右键,选择“以管理员身份运行”
如下图

RamDisk2.png (36.88 KB)
2008-8-28 09:49

打开后,输入:BCDedit /set nx AlwaysOff
然后再输入:BCDedit /set PAE ForceEnable

RamDisk3.png (60.54 KB)
2008-8-28 09:49

第四步,vista用户和xp用户都要执行:
在RamDisk的文件夹里有个叫做ram4g.reg的注册表文件,双击,将它导入系统

第五步,双击RamDisk.exe文件,运行程序(vista用户需要右键,选择“以管理员身份 运行”)

RamDisk4.png (91.87 KB)
2008-8-28 09:49

(点了Install之后如果提示重启,那就重启一下)

这时候,先别忙着点OK,再睁大眼睛确认一下,看看是不是都选择对了。

然后,再ctrl alt del调出任务管理器,放在前面,准备观察虚拟硬盘时内存的变化。

可以点ok了,RamDisk会花费几秒钟的时间来从内存中虚拟一块硬盘出来。
请仔细观察你的已使用内存量以及未使用的内存量。
如果创建完毕后,已使用的内存量增加的部分恰好与你创建的虚拟硬盘容量接近,未使用的内存容量减少了那么多,很遗憾,你没有利用系统未使用的内存虚拟硬盘,肯定是哪里操作出错了,只能重来。

如果内存使用量和未使用量基本没有变化,那我恭喜你,你的4G内存已经完全发挥出作用了!

创建结束的时候可能会提示重新启动计算机。根据我试验的经验,只有提示重启机器才是使用的未识别内存,否则就是从现有系统使用的内存里划分出来的。


RamDisk5.png (42.86 KB)
2008-8-28 09
:49

下面,就需要把一些临时文件夹转移到虚拟硬盘里了。

在“我的电脑”点右键,选择属性。
vista用户是在“计算机”上点右键,选择属性,然后再选择“高级系统设置”

在打开的窗口选择“高级”选项卡,点击“环境变量”按钮


RamDisk6.png (38.13 KB)
2008-8-28 09:49

在打开的窗口修改以下4个环境变量,改成图片显示的值即可(盘符要与你创建的盘符一致)


RamDisk7.png (31.58 KB)
2008-8-28 09:49

你可以自己选择虚拟硬盘下的路径,但是推荐创建在其下的TEMP文件夹下,因为TEMP是它默认就有的文件夹,放在别的地方可能某些软件第一次运行的时候会有错(因为文件夹不存在。我改到别的文件夹下,每次开机瑞星的监控都不能正常打开)

最后,把IE的临时文件夹也扔进来:


RamDisk8.png (75.45 KB)
2008-8-28 09:49

现在,再重启一下机器,让上面的修改都生效。
之后,你的4G内存就充分发挥作用了。

当然,内存没有4G的朋友也可以这么做,给系统提提速,减少些垃圾,但是不要分的这么大,毕竟那样是分出来一些可使用的就少了一些。

无边的select,去掉select的蓝边

有时候觉得xp上select的默认蓝边很难看,使用以下语句可以去掉select的边,其实是把它隐藏了
<span style="border:1px solid #ccc;position:absolute;overflow:hidden">
 <select style="margin:-1px;">
  <option>这个东西看起来更简单</option>
  <option>但是总是要求position:absolute</option>
  <option>还要注意:select & span 要写在一行上</option>
 </select>
</span>
span必须加上position:absolute才行,但好像又不会绝对定位,ie测试通过

点击后直接弹出保存文件的对话框,而不用弹出新窗口

一般的直接下载文件的代码如下:
System.IO.FileInfo file = new System.IO.FileInfo("F:\\mp3\\mp3\\茉莉花.mp3");
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.Charset="GB2312";
Response.ContentEncoding=System.Text.Encoding.UTF8;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename="+Server.UrlEncode("茉莉花.mp3"));
Response.AddHeader("Content-Length", file.Length.ToString());
Response.WriteFile(file.FullName);
Response.Flush();
Response.End();

另一种对于大文件,我们用上述代码不是较好,因为上述代码是将文件全缓存于服务器后才输出的,如果你的服务器流量大,且文件较大,不建议用以上方法,下面的代码其实就是把文件进行了分隔,慢慢的输出到客户端!
public static bool ResponseFile(HttpRequest _Request,HttpResponse _Response,string _fileName,string _fullPath, long _speed)
  {
   try
   {
    FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
    BinaryReader br = new BinaryReader(myFile);
    try
    {
     _Response.AddHeader("Accept-Ranges", "bytes");
     _Response.Buffer = false;
     long fileLength = myFile.Length;
     long startBytes = 0;
    
     int pack = 10240; //10K bytes
     int sleep = (int)Math.Floor(1000 * pack / _speed) + 1;
     if (_Request.Headers["Range"] != null)
     {
      _Response.StatusCode = 206;
      string[] range = _Request.Headers["Range"].Split(new char[] {'=', '-'});
      startBytes = Convert.ToInt64(range[1]);
     }
     _Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
     if (startBytes != 0)
     {
      _Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength-1, fileLength));
     }
     _Response.AddHeader("Connection", "Keep-Alive");
     _Response.ContentType = "application/octet-stream";
     _Response.AddHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(_fileName,System.Text.Encoding.UTF8) );
 
     br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
     int maxCount = (int) Math.Floor((fileLength - startBytes) / pack) + 1;

 

     for (int i = 0; i < maxCount; i++)
     {
      if (_Response.IsClientConnected)
      {
       _Response.BinaryWrite(br.ReadBytes(pack));
       Thread.Sleep(sleep);
      }
      else
      {
       i=maxCount;
      }
     }
     _Response.Flush();
    }
    catch
    {
     return false;
    }
    finally
    {
     br.Close();
     myFile.Close();
    }
   }
   catch
   {
    return false;
   }
   return true;
  }

说明:
 _Response.Flush();把当前缓冲区中的数据输出到客户端

C# 用VB.net 函数库来实现全角与半角转换、简体和繁体转换

        /// 转全角的函数(SBC case)
        ///
        /// 任意字符串
        /// 全角字符串
        ///
        ///全角空格为12288,半角空格为32
        ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
        ///       
        public string ToSBC(string input)
        {
            //半角转全角:
            char[] c=input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i]==32)
                {
                    c[i]=(char)12288;
                    continue;
                }
                if (c[i]<127)
                    c[i]=(char)(c[i]+65248);
            }
            return new string(c);               
        }

        /**////
        /// 转半角的函数(DBC case)
        ///
        /// 任意字符串
        /// 半角字符串
        ///
        ///全角空格为12288,半角空格为32
        ///其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
        ///
        public string ToDBC(string input)
        {   
            char[] c=input.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i]==12288)
                {
                   c[i]= (char)32;
                    continue;
                }
                if (c[i]>65280 && c[i]<65375)
                    c[i]=(char)(c[i]-65248);
            }   
            return new string(c);
        }
2.C#中直接调用VB.NET的函数,兼论半角与全角、简繁体中文互相转化

在C#项目中添加引用Microsoft.VisualBasic.dll, 可以在C#程序中直接使用VB.NET中丰富的函数 
 

 // 命令行编译 : csc /r:Microsoft.VisualBasic.dll Test.cs
 // 如果是用 Visual Studio .NET IDE, 请按以下方法为项目添加引用:
 // 打开[解决方案资源管理器], 右击项目名称, 选择[添加引用],
 // 从列表中选择 Microsoft Visual Basic .NET Runtime 组件.

 using Microsoft.VisualBasic;

class Test
{
  static void Main()
  {
    string s = "空军]";
    System.Console.WriteLine(s);
    s = Strings.StrConv(s, VbStrConv.Wide              , 0); // 半角转全角
    s = Strings.StrConv(s, VbStrConv.TraditionalChinese, 0); // 简体转繁体
    System.Console.WriteLine(s);
    s = Strings.StrConv(s, VbStrConv.ProperCase        , 0); // 首字母大写
    s = Strings.StrConv(s, VbStrConv.Narrow            , 0); // 全角转半角
    s = Strings.StrConv(s, VbStrConv.SimplifiedChinese , 0); // 繁体转简体
    System.Console.WriteLine(s);
  }
}

C# String.Format格式的详细说明,供参考

几种变量格式化的参数说明:

C#格式化数值结果表

字符

说明

示例

输出

C 货币 string.Format("{0:C3}", 2) $2.000
D 十进制 string.Format("{0:D3}", 2) 002
E 科学计数法 1.20E+001 1.20E+001
G 常规 string.Format("{0:G}", 2) 2
N 用分号隔开的数字 string.Format("{0:N}", 250000) 250,000.00
X 十六进制 string.Format("{0:X000}", 12) C


string.Format("{0:000.000}", 12.2) 012.200

(全文 ...)