随笔-74  评论-68  文章-1  trackbacks-2
  2008年11月28日

最近在看本书 pro javascript,受益匪浅。

在看closure这章的时候,作者推荐 http://jibbering.com/faq/faq_notes/closures.html 这篇文章。

很不错的一篇文章,很深入,所以看得很慢。看到有段代码有点意思,是关于prototype chain的:

Code 


posted @ 2008-11-28 14:30 Ryan Gene 阅读(6) | 评论 (0)编辑
  2008年11月18日

 1 function addLoadEvent(func)
 2 {
 3     var oldonload = window.onload;
 4     if (typeof window.onload != 'function')
 5     {
 6         window.onload = func;
 7     }
 8     else
 9     {
10         window.onload = function()
11         {
12             oldonload();
13             func();
14         }
15     }
16 
posted @ 2008-11-18 16:50 Ryan Gene 阅读(12) | 评论 (0)编辑
  2008年9月8日

http://zhidao.baidu.com/question/1798929.html

“IIS配置401错误”完美解决方案(54powerman) 
1、错误号401.1 
症状:HTTP错误401.1-未经授权:访问由于凭据无效被拒绝。 
分析: 
由于用户匿名访问使用的账号(默认是IUSR_机器名)被禁用,或者没有权限访问计算机,将造成用户无法访问。 
解决方案: 
(1)查看IIS管理器中站点安全设置的匿名帐户是否被禁用,如果是,请尝试用以下办法启用: 
控制面板->管理工具->计算机管理->本地用户和组,将IUSR_机器名账号启用。如果还没有解决,请继续下一步。 
(2)查看本地安全策略中,IIS管理器中站点的默认匿名访问帐号或者其所属的组是否有通过网络访问服务器的权限,如果没有尝试用以下步骤赋予权限: 
开始->程序->管理工具->本地安全策略->安全策略->本地策略->用户权限分配,双击“从网络访问此计算机”,添加IIS默认用户或者其所属的组。 
注意:一般自定义IIS默认匿名访问帐号都属于组,为了安全,没有特殊需要,请遵循此规则。 

2、错误号401.2 
症状:HTTP错误401.2-未经授权:访问由于服务器配置被拒绝。 
原因:关闭了匿名身份验证 
解决方案: 
运行inetmgr,打开站点属性->目录安全性->身份验证和访问控制->选中“启用匿名访问”,输入用户名,或者点击“浏览”选择合法的用户,并两次输入密码后确定。 

3、错误号:401.3 
症状:HTTP错误401.3-未经授权:访问由于ACL对所请求资源的设置被拒绝。 
原因:IIS匿名用户一般属于Guests组,而我们一般把存放网站的硬盘的权限只分配给administrators组,这时候按照继承原则,网站文件夹也只有administrators组的成员才能访问,导致IIS匿名用户访问该文件的NTFS权限不足,从而导致页面无法访问。 
解决方案: 
给IIS匿名用户访问网站文件夹的权限,方法:进入该文件夹的安全选项,添加IIS匿名用户,并赋予相应权限,一般是读、写。

posted @ 2008-09-08 17:08 Ryan Gene 阅读(265) | 评论 (1)编辑
  2008年8月26日

 link: http://neo.dzygn.com/archive/2004/05/preserving-scope-in-javascript

 
Preserving Scope in JavaScript
Solution #3: Closures

In JavaScript you can share variables between functions. Such a shared variable is called a closure. It is said, though, that closures require quite a lot more memory than ordinary properties.

When we use closures the code looks like this:

function MyClass(){
var self = this; /* reference to the right scope */
this.message = "hello world";
this.talk = function talk(){ /* remember: because I named the function I can access it directly by it's name */
if(this != self){
return talk.apply(self, arguments);
};
alert(this.message);
};
};
var instance = new MyClass();
setTimeout(instance.talk, 1000);


Comments

   1.
      trs wrote:

      Not a very eloquent solution, at some point there is still global code running so the scope context doesn’t encapsulate the execution. The bottom line is that with functions like setTimeout, the first argument will always run in global scope and there is nothing you can do about it. Probably best use a closure and be careful with references to binded COM objects i.e. DOM nodes (especially in Microsoft Internet Explorer, the MSFT GC has trouble cleaning up after non-JScript owned objects).

      May 8, 2004 @ 7:03 pm. Type: Comment. Permalink.
   2.
      David Schontzler wrote:

      I know I’m replying to this real late, but I thought I should point it out…

      The most eloquent solution would be to just replace all references to this with self. That way you don’t have to do any scope checking or rewrite your code structure.

      September 13, 2004 @ 2:18 am. Type: Comment. Permalink.
   3.
      Mark Wubben wrote:

      David, quite true. This was also pointed out in the linked DHTMLCentral posts (which was lost last Friday).

      As you can see in the sIFR code this is more or less the way I’m (currently) hacking.

      September 13, 2004 @ 3:05 pm. Type: Comment. Permalink.
   4.
      Gustavo Armagno wrote:

      If I want to pass the value of a variable to an event, there’s another ‘dirty’ (what it’s not dirty in js?) way to solve the problem:

      Not working:

      function createAnchor() {
      var str = “hello!!!”;
      var anchor = document.createElement("a");
      anchor.href = “”;
      anchor.onclick = function() {
      alert(str);
      }
      … [appendChild to some document element]
      }

      Variable str is out of the scope when the event is triggered.

      Solution:

      function createAnchor() {
      var str = “hello!!!”;
      var anchor = document.createElement("a");
      anchor.href = “”;
      var evalStr = “anchor.onclick = function() { alert(’” + str + ”‘); }”;
      eval(evalStr);
      … [appendChild to some document element]
      }

      January 20, 2005 @ 2:55 pm. Type: Comment. Permalink.
   5.
      Mark Wubben wrote:

      Gustavo, actually your first example will work because the onclick event is a closure in which str does exist.

      January 20, 2005 @ 2:59 pm. Type: Comment. Permalink.
   6.
      Brent Hendricks wrote:

      Mark,

      I have a similar situation to the one Gustavo posted, but in my case I’m setting several onclick handlers in a loop with str as the iteration variable. So even though the variable exists in the handler, it has the wrong value (the final iteration value). Is there a way to pass the value of a variable without using evalStr?

      January 22, 2005 @ 7:36 pm. Type: Comment. Permalink.
   7.
      Mark Wubben wrote:

      Brent, interesting question. Here’s an idea (haven’t tested it):

      while(str != null){

          node.onclick = (function(str){

          return function(){ alert(str); }

          })(str);

          };

      What this does is calling an anonymous function in block scope with the variable as it’s argument. This function returns a closure in which the variable is available. A new closure is returned every time the anonymous function is invoked, thus the problem of referencing the iteration variable is solved.

 
posted @ 2008-08-26 23:05 Ryan Gene 阅读(42) | 评论 (0)编辑

CSS hack:区分IE6,IE7,firefox

区别IE6与FF:
      background:orange;*background:blue;

区别IE6与IE7:
       background:green !important;background:blue;
区别IE7与FF:
       background:orange; *background:green;
区别FF,IE7,IE6:
       background:orange;*background:green !important;*background:blue;

 

注:IE都能识别*;标准浏览器(如FF)不能识别*;
IE6能识别*,但不能识别 !important,
IE7能识别*,也能识别!important;
FF不能识别*,但能识别!important;
  IE6 IE7 FF
* ×
!important ×

另外再补充一个,下划线"_",
IE6支持下划线,IE7和firefox均不支持下划线。(推荐)

于是大家还可以这样来区分IE6,IE7,firefox
: background:orange;*background:green;_background:blue;

注:不管是什么方法,书写的顺序都是firefox的写在前面,IE7的写在中间,IE6的写在最后面。

posted @ 2008-08-26 16:33 Ryan Gene 阅读(43) | 评论 (0)编辑
  2008年8月12日
 1<script type="text/javascript">  
 2function getFileSize(filePath)  
 3{  
 4    var image=new Image();  
 5    image.dynsrc=filePath;  
 6    alert(image.fileSize);  
 7 }
  
 8 </script>  
 9 <body>  
10 <INPUT TYPE="file" NAME="file" SIZE="30" onchange="getFileSize(this.value)">  
11 </body> 
posted @ 2008-08-12 17:18 Ryan Gene 阅读(154) | 评论 (0)编辑
  2008年7月17日

Super. Clear, easy and it's working perfect on Windows. Anyway, you must be in cmd in the folder where you installed VMWare and write the full path to the disk file.

Ex: C:"Program Files"VMware"VMware Server> vmware-vdiskmanager -x 15GB "D:"VMWare Images"Win2003VM"NLD9-cl1.vmdk"

posted @ 2008-07-17 16:44 Ryan Gene 阅读(181) | 评论 (0)编辑
ref http://www.xs4all.nl/~ppk/js/flash.html

 1<SCRIPT LANGUAGE="Javascript">
 2<!--
 3
 4var flashinstalled = 0;
 5var flashversion = 0;
 6MSDetect = "false";
 7if (navigator.plugins && navigator.plugins.length)
 8{
 9    x = navigator.plugins["Shockwave Flash"];
10    if (x)
11    {
12        flashinstalled = 2;
13        if (x.description)
14        {
15            y = x.description;
16            flashversion = y.charAt(y.indexOf('.')-1);
17        }

18    }

19    else
20        flashinstalled = 1;
21    if (navigator.plugins["Shockwave Flash 2.0"])
22    {
23        flashinstalled = 2;
24        flashversion = 2;
25    }

26}

27else if (navigator.mimeTypes && navigator.mimeTypes.length)
28{
29    x = navigator.mimeTypes['application/x-shockwave-flash'];
30    if (x && x.enabledPlugin)
31        flashinstalled = 2;
32    else
33        flashinstalled = 1;
34}

35else
36    MSDetect = "true";
37
38// -->
39</SCRIPT>
40
41<SCRIPT LANGUAGE="VBScript">
42
43on error resume next
44
45If MSDetect = "true" Then
46    For i = 2 to 6
47        If Not(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & i))) Then
48
49        Else
50            flashinstalled = 2
51            flashversion = i
52        End If
53    Next
54End If
55
56If flashinstalled = 0 Then
57    flashinstalled = 1
58End If
59
60</SCRIPT>


posted @ 2008-07-17 15:35 Ryan Gene 阅读(76) | 评论 (0)编辑
  2008年6月25日
 1string s = “<Test><a></a></Test>”;
 2System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
 3doc.LoadXml(s);
 4System.IO.MemoryStream ms = new System.IO.MemoryStream();
 5System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(ms, Encoding.UTF8);
 6xmlWriter.Indentation = 4;
 7xmlWriter.Formatting = System.Xml.Formatting.Indented;
 8doc.WriteContentTo(xmlWriter);
 9xmlWriter.Close();
10string result = Encoding.UTF8.GetString(ms.ToArray());
posted @ 2008-06-25 11:24 Ryan Gene 阅读(158) | 评论 (0)编辑
  2008年6月19日
firefox 3中,有些插件安装的时候不能通过版本检测,有时候不是真正的不兼容,而是作者在开发的时候,限制了最大版本号。

比如我常用的speak it 插件,暂时还没有3.0版本。

要解决这个问题,我们可以把插件的xpi先下载下来,重命名成.zip文件,解压缩后,用记事本打开install.rdf文件,里面有一个<em:maxVersion>2.0.0.*</em:maxVersion>节点,只要改成<em:maxVersion>3.0.*</em:maxVersion>就可以了。然后保存,把目录打包,重命名成.xpi文件,用firefox 打开,安装即可。

当然,不是所有的插件都可以用这种方法解决的,呵呵~

配合neospeech Wang,终于又可以让ff朗读中文啦,哈哈(读英文我用neospeech的paul,发音还挺标准的)

有兴趣的朋友可以下载玩玩 :)
改过的speak it 插件
posted @ 2008-06-19 22:08 Ryan Gene 阅读(637) | 评论 (2)编辑