﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Ginew.Z 的博客-随笔分类-JavaScript</title><link>http://www.blogjava.net/ginew/category/9093.html</link><description>一切，为了让生活更简单、更自然</description><language>zh-cn</language><lastBuildDate>Thu, 01 Mar 2007 15:36:27 GMT</lastBuildDate><pubDate>Thu, 01 Mar 2007 15:36:27 GMT</pubDate><ttl>60</ttl><item><title>href=# vs href=void(0)</title><link>http://www.blogjava.net/ginew/archive/2006/11/17/81734.html</link><dc:creator>无风之雨</dc:creator><author>无风之雨</author><pubDate>Fri, 17 Nov 2006 04:15:00 GMT</pubDate><guid>http://www.blogjava.net/ginew/archive/2006/11/17/81734.html</guid><wfw:comment>http://www.blogjava.net/ginew/comments/81734.html</wfw:comment><comments>http://www.blogjava.net/ginew/archive/2006/11/17/81734.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ginew/comments/commentRss/81734.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ginew/services/trackbacks/81734.html</trackback:ping><description><![CDATA[
		<h3 class="heading-1">href="#" vs. href="javascript:void(0)"</h3>开发的时候有时需要用link(&lt;a&gt;)来触发一些javascript事件，所以常常可以看到如下的代码： 
<p class="paragraph"></p><div class="code"><pre>&lt;a href=<span class="java-quote">"javascript:void(0)"</span> onclick=<span class="java-quote">"doSomething();<span class="java-keyword">return</span><span class="java-keyword">false</span>;"</span>&gt;Link&lt;/a&gt;</pre></div><p class="paragraph">这是一个曾经被多次讨论过的问题，长期以来，我也一直是这样写的。读了 <span class="nobr"><img alt="&gt;&gt;" src="http://ajaxcn.org/theme/images/Icon-Extlink.png" border="0" /><a href="http://blog.reindel.com/2006/08/11/a-hrefjavascriptvoid0-avoid-the-void/" target="_blank">a href=”javascript:void(0);” — avoid the void</a></span> 之后，我认同了作者的意见。下面的写法确实更合理： 
</p><p class="paragraph"></p><div class="code"><pre>&lt;a href=<span class="java-quote">"#"</span> onclick=<span class="java-quote">"doSomething();<span class="java-keyword">return</span><span class="java-keyword">false</span>;"</span>&gt;Link&lt;/a&gt;</pre></div><p class="paragraph">或者 
</p><p class="paragraph"></p><div class="code"><pre>&lt;script type=<span class="java-quote">"javascript"</span>&gt;
function doSomething() {
  //doSomething
  <span class="java-keyword">return</span><span class="java-keyword">false</span>;
}
&lt;/script&gt;
&lt;a href=<span class="java-quote">"#"</span> onclick=<span class="java-quote">"<span class="java-keyword">return</span> doSomething();"</span>&gt;Link&lt;/a&gt;</pre></div><p class="paragraph">以往大家不使用"#"的问题是，这将导致点击链接时页面跳回页面顶部，但通过 return false 语句将使得浏览器忽略链接的默认动作，从而避免了此问题。 
</p><p class="paragraph"><b class="bold">youngpup</b> 更有意思，他在<span class="nobr"><img alt="&gt;&gt;" src="http://ajaxcn.org/theme/images/Icon-Extlink.png" border="0" /><a href="http://boring.youngpup.net/2003/popups" target="_blank">How to Create Pop-Up Windows</a></span> 中言辞激烈的倡导大家永远永远永远不要使用 <b class="bold">javascript:</b> 伪协议： 
</p><p class="paragraph"></p><blockquote class="quote">Never, ever, ever use the javascript: pseudo-protocol for anything, ever ever ever ever again. Please. Pretty please. </blockquote><p class="paragraph">他的解决方案是： </p><div class="code"><pre>&lt;a 
  href=<span class="java-quote">"http://google.com/"</span> 
  onclick=<span class="java-quote">"window.open(<span class="java-keyword">this</span>.href, 'popupwindow', 
  'width=400,height=300,scrollbars,resizable'); 
  <span class="java-keyword">return</span><span class="java-keyword">false</span>;"</span>&gt;</pre></div><p class="paragraph">这样的好处就是可以保存到书签或者收藏夹，可以左键单击，也可以右键使用！ </p><img src ="http://www.blogjava.net/ginew/aggbug/81734.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ginew/" target="_blank">无风之雨</a> 2006-11-17 12:15 <a href="http://www.blogjava.net/ginew/archive/2006/11/17/81734.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于IE无法打开INTERNET站点的错</title><link>http://www.blogjava.net/ginew/archive/2006/04/19/41975.html</link><dc:creator>无风之雨</dc:creator><author>无风之雨</author><pubDate>Wed, 19 Apr 2006 10:14:00 GMT</pubDate><guid>http://www.blogjava.net/ginew/archive/2006/04/19/41975.html</guid><wfw:comment>http://www.blogjava.net/ginew/comments/41975.html</wfw:comment><comments>http://www.blogjava.net/ginew/archive/2006/04/19/41975.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ginew/comments/commentRss/41975.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ginew/services/trackbacks/41975.html</trackback:ping><description><![CDATA[        今天新页面上线，很多同事报告说页面打开到一半，经常跳出无法打开Internet站点的错误，然后页面会跳转到DNS错误的页面。<br /><br />      <img height="122" alt="notload.jpg" src="http://www.blogjava.net/images/blogjava_net/ginew/notload.jpg" width="494" border="0" /><br />        <br />        这个问题我以前遇到过，一直没有详细的去深究原因，只是以为是服务器关闭连接太快的原因。今天发现这个问题出的很频繁，服务器方面没有改什么，只是上传了新的页面程序而已，应该不会和服务器有关。在对页面进行分析，并搜索了一下网上，发现原来是js在document还没完全load完的时候就试图改变其值导致。<br /><br />        因此对js做如下改变：<br /><br />原js：<br /><br />     window.settimeout("go()",500);<br />     function go(){<br />    .......<br />     }<br /><br />改成：<br /><br />var go_i=window.setInterval("go()",500);<br />function go(){<br />   if(document.readyState=="complete"){<br />      window.clearInterval(go2_i);<br />    }<br />    else return;<br />    ........<br />}<br />目的就是让他一定要在document完成后才执行那个操作<img src ="http://www.blogjava.net/ginew/aggbug/41975.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ginew/" target="_blank">无风之雨</a> 2006-04-19 18:14 <a href="http://www.blogjava.net/ginew/archive/2006/04/19/41975.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>document.domain与域名的问题</title><link>http://www.blogjava.net/ginew/archive/2006/04/13/40850.html</link><dc:creator>无风之雨</dc:creator><author>无风之雨</author><pubDate>Thu, 13 Apr 2006 03:54:00 GMT</pubDate><guid>http://www.blogjava.net/ginew/archive/2006/04/13/40850.html</guid><wfw:comment>http://www.blogjava.net/ginew/comments/40850.html</wfw:comment><comments>http://www.blogjava.net/ginew/archive/2006/04/13/40850.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ginew/comments/commentRss/40850.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ginew/services/trackbacks/40850.html</trackback:ping><description><![CDATA[
		<p>以前如果要使iframe里面的脚本能访问parent的内容，但iframe和parent的二级域名相同，那一般都会在两者都写上document.domain="xxx.com" 以放宽访问权限。<br /><br />今天发现，如果iframe和parent在同一个三级域名下，比如都是aa.bb.com，那设了document.domain反而会造成访问拒绝。<br /><br />查了下MSDN，有如下解释：<br /><br /></p>
		<p class="clsRef">Remarks</p>
		<blockquote>
				<p>The property initially returns the host name of the server from which the page is served. The property can be assigned the domain suffix to allow sharing of pages across frames. For example, a page in one frame from home.microsoft.com and a page from www.microsoft.com initially would not be able to communicate with each other. However, by setting the <b>domain</b> property of both pages to the suffix "microsoft.com", you ensure that both pages are considered secure and access is available between the pages. </p>
				<p>When you set the <b>domain</b> property, use the domain name determined by the server rather than by the client browser. </p>
				<p>All the pages on different hosts must have the <b>domain</b> property explicitly set to the same value to communicate successfully with each other. For example, the value of the <b>domain</b> property of a page on the host microsoft.com would be "microsoft.com" by default. It might seem logical that if you set the <b>domain</b> property of a page on another host named msdn.microsoft.com to "microsoft.com," that the two pages could communicate with each other. However, this is not the case unless you have also explicitly set the <b>domain</b> property of the page on microsoft.com to "microsoft.com". </p>
				<p>Furthermore, this property cannot be used to allow cross-frame communication among frames with different domain suffixes. For example, a page in one frame from www.microsoft.com and a page in another frame from www.msn.com would not be able to communicate with each other even if the <b>domain</b> property of both pages was set to the suffix "microsoft.com".</p>
				<div class="clsNote">
						<b>
								<img alt="security note" src="http://msdn.microsoft.com/workshop/graphics/UI_security_bang_16.gif" /> Security Alert</b>  Using this property incorrectly can compromise the security of your Web site. Set the <b>domain</b> property only if you must allow cross-domain scripting. Use a value determined on the server. Setting this property to a value determined on the client (like through the <a href="http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_location.asp">location</a> object) could expose your site to attack from another site through Domain Name System (DNS) manipulation. For more information, see <a href="http://msdn.microsoft.com/workshop/author/dhtml/sec_dhtml.asp">Security Considerations: Dynamic HTML</a>.</div>
				<p>For more information on domain security, see <a href="http://msdn.microsoft.com/workshop/author/om/xframe_scripting_security.asp">About Cross-Frame Scripting and Security</a>.</p>
		</blockquote>
<img src ="http://www.blogjava.net/ginew/aggbug/40850.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ginew/" target="_blank">无风之雨</a> 2006-04-13 11:54 <a href="http://www.blogjava.net/ginew/archive/2006/04/13/40850.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MSDN里面关于DHTML的文档</title><link>http://www.blogjava.net/ginew/archive/2006/04/09/40077.html</link><dc:creator>无风之雨</dc:creator><author>无风之雨</author><pubDate>Sun, 09 Apr 2006 04:18:00 GMT</pubDate><guid>http://www.blogjava.net/ginew/archive/2006/04/09/40077.html</guid><wfw:comment>http://www.blogjava.net/ginew/comments/40077.html</wfw:comment><comments>http://www.blogjava.net/ginew/archive/2006/04/09/40077.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ginew/comments/commentRss/40077.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ginew/services/trackbacks/40077.html</trackback:ping><description><![CDATA[
		<p>我有chm，但那个已经比较老了，最新的还是在MSDN，查每个元素的属性方法，style的写法，非常有用<br /><br /><a href="http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp">http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/dhtml_reference_entry.asp</a></p>
<img src ="http://www.blogjava.net/ginew/aggbug/40077.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ginew/" target="_blank">无风之雨</a> 2006-04-09 12:18 <a href="http://www.blogjava.net/ginew/archive/2006/04/09/40077.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>昨天发现的关于a 和css,js的一些冲突</title><link>http://www.blogjava.net/ginew/archive/2006/04/09/40076.html</link><dc:creator>无风之雨</dc:creator><author>无风之雨</author><pubDate>Sun, 09 Apr 2006 04:15:00 GMT</pubDate><guid>http://www.blogjava.net/ginew/archive/2006/04/09/40076.html</guid><wfw:comment>http://www.blogjava.net/ginew/comments/40076.html</wfw:comment><comments>http://www.blogjava.net/ginew/archive/2006/04/09/40076.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/ginew/comments/commentRss/40076.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/ginew/services/trackbacks/40076.html</trackback:ping><description><![CDATA[
		<p>    我做一个网页，原先的设想是，一个页面上有数个DIV，我只显示其中一个DIV，其他的隐藏，当我点击页面头部的链接的时候，js把所有DIV都隐藏，然后显示我点击链接所代表的DIV。<br />    问题是出来了。当第一个DIV显示后，正在读取里面的元素，比如图片的时候，我点击头部链接，那图片就不会继续读了，就算我切换回来，它也停在那里了。<br />     原先我以为是隐藏方式的问题，但我用了dislplay和visibility，都一样。后来同事启发了一下，说以前曾做过一个广告图片，当他点击关闭图片的链接的时候，会把图片隐藏，但会导致整个页面上所有的动画都停止的现象，他用的是&lt;a href=# onclick="closeit()"&gt;来关的。后来他把href=#去掉了，并加上style="cursor:hand"来显示手形。这样图片可以隐藏掉，页面也不会有任何影响。<br />     我照着把头部的链接改了，把原先的href="javascript:showit()"改成了onclick，至此问题解除，在我切换到其他DIV的时候，隐藏的DIV会继续读取页面元素。<br /><br />    我想，出现这种情况，可能是因为浏览器把href当作是页面跳转的语句，就算页面实际上没有转，它也认为原页面已经被跳转掉了，再读取上面元素已经没有意义，所以就全部停了。</p>
<img src ="http://www.blogjava.net/ginew/aggbug/40076.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/ginew/" target="_blank">无风之雨</a> 2006-04-09 12:15 <a href="http://www.blogjava.net/ginew/archive/2006/04/09/40076.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>