??xml version="1.0" encoding="utf-8" standalone="yes"?>精品国产欧美日韩一区二区三区,永久在线免费观看,99精品欧美一区二区三区http://www.aygfsteel.com/sealyu/category/45313.html--- The devil's in the Detailszh-cnTue, 22 Jun 2010 23:23:06 GMTTue, 22 Jun 2010 23:23:06 GMT60js获取光标位置Q{Q?/title><link>http://www.aygfsteel.com/sealyu/archive/2010/06/22/324220.html</link><dc:creator>seal</dc:creator><author>seal</author><pubDate>Tue, 22 Jun 2010 15:17:00 GMT</pubDate><guid>http://www.aygfsteel.com/sealyu/archive/2010/06/22/324220.html</guid><wfw:comment>http://www.aygfsteel.com/sealyu/comments/324220.html</wfw:comment><comments>http://www.aygfsteel.com/sealyu/archive/2010/06/22/324220.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sealyu/comments/commentRss/324220.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sealyu/services/trackbacks/324220.html</trackback:ping><description><![CDATA[/**<br /> * 获取光标所在的字符位置<br /> * @param obj 要处理的控g, 支持文本域和输入?br /> * @author hotleave<br /> */<br /> <br /> <textarea id="runcode0" class="codeTextarea" cols="60" rows="15"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=GBK" /> <title>js获取光标位置</title> <script type="text/javascript"> /** * 获取光标所在的字符位置 * @param obj 要处理的控g, 支持文本域和输入? * @author hotleave */ function getPosition(obj){ //alert(obj.tagName); var result = 0; if(obj.selectionStart){ //非IE览? result = obj.selectionStart }else{ //IE var rng; if(obj.tagName == "TEXTAREA"){ //如果是文本域 rng = event.srcElement.createTextRange(); rng.moveToPoint(event.x,event.y); }else{ //输入? rng = document.selection.createRange(); } rng.moveStart("character",-event.srcElement.value.length); result = rng.text.length; } return result; } function getValue(obj){ var pos = getPosition(obj); //alert(pos); alert(obj.value.substr(0,pos)+" [q里是添加的内容] "+obj.value.substr(pos,obj.value.length)); } </script> </head> <body> <input type="text" value="你好,Amethyst!" onmouseup="getValue(this)" style="display:block"> <textarea rows="6" cols="60" onmouseup="getValue(this)">Amethyst, 你好.</textarea> </body> </html> </textarea><br /> <input id="0" onclick="runCode(this.id)" value="q行代码" type="button" />  <button id="0" onclick="doCopy(this.id)">复制代码</button>  <label id="0" onclick="saveCode(this.id)" class="saveLabel">另存代码</label>  提示Q您 可以先修攚w分代码再q行<br /> <br /> <br /> <textarea id="runcode1" class="codeTextarea" cols="60" rows="15"><html> <head> <title>js获取光标位置</title> <style> body,td{ font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; } </style> <script type="text/javascript"> var start=0; var end=0; function add(){ var textBox = document.getElementById("ta"); var pre = textBox.value.substr(0, start); var post = textBox.value.substr(end); textBox.value = pre + document.getElementById("inputtext").value + post; } function savePos(textBox){ //如果是Firefox(1.5)的话Q方法很? if(typeof(textBox.selectionStart) == "number"){ start = textBox.selectionStart; end = textBox.selectionEnd; } //下面是IE(6.0)的方法,ȝ得很Q还要计上'"n' else if(document.selection){ var range = document.selection.createRange(); if(range.parentElement().id == textBox.id){ // create a selection of the whole textarea var range_all = document.body.createTextRange(); range_all.moveToElementText(textBox); //两个rangeQ一个是已经选择的text(range)Q一个是整个textarea(range_all) //range_all.compareEndPoints()比较两个端点Q如果range_all比range更往?further to the left)Q则 //q回于0的|则range_all往右移一点,直到两个range的start相同? // calculate selection start point by moving beginning of range_all to beginning of range for (start=0; range_all.compareEndPoints("StartToStart", range) < 0; start++) range_all.moveStart('character', 1); // get number of line breaks from textarea start to selection start and add them to start // 计算一?n for (var i = 0; i <= start; i ++){ if (textBox.value.charAt(i) == '"n') start++; } // create a selection of the whole textarea var range_all = document.body.createTextRange(); range_all.moveToElementText(textBox); // calculate selection end point by moving beginning of range_all to end of range for (end = 0; range_all.compareEndPoints('StartToEnd', range) < 0; end ++) range_all.moveStart('character', 1); // get number of line breaks from textarea start to selection end and add them to end for (var i = 0; i <= end; i ++){ if (textBox.value.charAt(i) == '"n') end ++; } } } document.getElementById("start").value = start; document.getElementById("end").value = end; } </script> </head> <body> <form action="a.cgi"> <table border="1" cellspacing="0" cellpadding="0"> <tr> <td>start: <input type="text" id="start" size="3"/></td> <td>end: <input type="text" id="end" size="3"/></td> </tr> <tr> <td colspan="2"> <textarea id="ta" onKeydown="savePos(this)" onKeyup="this.value=this.value.replace(/["Q]/g,',');savePos(this);" onmousedown="savePos(this)" onmouseup="savePos(this)" onfocus="savePos(this)" rows="14" cols="50"></textarea> </td> </tr> <tr> <td><input type="text" id="inputtext" /></td> <td><input type="button" onClick="add()" value="Add Text"/></td> </tr> </table> </form> </body> </html> </textarea><br /> <input id="1" onclick="runCode(this.id)" value="q行代码" type="button" />  <button id="1" onclick="doCopy(this.id)">复制代码</button>  <label id="1" onclick="saveCode(this.id)" class="saveLabel">另存代码</label>  提示Q您 可以先修攚w分代码再q行 <img src ="http://www.aygfsteel.com/sealyu/aggbug/324220.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sealyu/" target="_blank">seal</a> 2010-06-22 23:17 <a href="http://www.aygfsteel.com/sealyu/archive/2010/06/22/324220.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> FCKeditor: Resolve “FCKeditorAPI is not defined?issuehttp://www.aygfsteel.com/sealyu/archive/2010/06/22/324103.htmlsealsealMon, 21 Jun 2010 16:12:00 GMThttp://www.aygfsteel.com/sealyu/archive/2010/06/22/324103.htmlhttp://www.aygfsteel.com/sealyu/comments/324103.htmlhttp://www.aygfsteel.com/sealyu/archive/2010/06/22/324103.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/324103.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/324103.htmlFCKeditor offers a complete JavaScript API so you can interact with it once the editor is loaded and running.

Once loaded, the editor registers a global object called FCKeditorAPI. This object offers the entry point to interact with any editor instance placed in a page.

NOTE: The FCKeditorAPI object will not be available during the page load. You need to wait for the editor to be loaded to use it.

Often, I see that people complain about a JavaScript error, “FCKeditorAPI is not defined”, when they try to use FCKeditorAPI.

For example

The following code will throw a JavaScript error when you try to use the FCKeditorAPI -

You can resolve the JavaScript error by adding a line of code (Line # 4) as shown below -

Hope this helps!



seal 2010-06-22 00:12 发表评论
]]>
IE和Safari中重命名html元素需要注意的问题http://www.aygfsteel.com/sealyu/archive/2010/06/11/323288.htmlsealsealThu, 10 Jun 2010 16:10:00 GMThttp://www.aygfsteel.com/sealyu/archive/2010/06/11/323288.htmlhttp://www.aygfsteel.com/sealyu/comments/323288.htmlhttp://www.aygfsteel.com/sealyu/archive/2010/06/11/323288.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/323288.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/323288.html
q两天在处理览器兼容的时候碰到很多问题,特别是在重新命名checkbox的时候,在IE和Safari中都到一些怪异的问题?br />
  1. IE中不能在q行旉命名元素?/li>
     按照微Y的解释,q行时是无法重命名的Q?br />      After some digging, I found an explanation in the MSDN DHTML reference, on the page describing the NAME Attribute.

The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a name attribute, include the attribute and value when using the createElement method.

后来扑ֈ国外的一帖子,扑ֈ一个解x法,那就是?a title="MSDN mergeAttributes Documentation" >mergeAttributes ҎQ模拟新Z个只有name不同的元素,q和之前的元素合qӞq样p辑ֈ重命名的效果了。代码如下:

var setElementName = function(el, newName) {

el 
= (typeof el === "string"? document.getElementById(el) : el;

el.name 
= newName;

if(/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { // Internet Explorer test 

el.mergeAttributes(document.createElement(
"<INPUT name='" + newName + "'/>"), false);

}

};

2. Safari中,如果用getElementsByName得到一个checkboxl,那么重命名的? 候,无法用for循环全部重命?br /> 例如Q?br />
var checkBoxes = document.getElementsByName("testCheckbox");
          
var checkBoxesSize = checkBoxes.length;
          
for (var i = checkBoxesSize - 1; i >= 0; i--) {
             
if (checkBoxes[i] && !checkBoxes[i].checked) {
                 setElementName(checkBoxes[i],
"testCheckbox-new");
             }
           }
q种情况在IE和Firefox下面都没有问题,全部的checkbox都会被成功的重命名?br /> 但是在Safari下面Q无法实现这个目的。经q调试发玎ͼ在Safari中,如果使用getElementsByName来得到这个checkboxl,那么在重命名的时候,如果使用for循环来依ơ进行,那么每重命名一个checkboxQsafari自动将q个元素从for循环中移除,q样q个循环在进行到一半的时候就会报错:checkBoxes[i][null]不是一个元素?br /> U结了一D|_本来打算想一个算法来解决q个问题Q后来突然想到另外一个简单一点的ҎQ?br /> 使用getElementsByTagNameҎ来得到所有元素,q从中筛选出对应的checkboxQ如果符合条Ӟ再重命名。这U情况下Q因Z用的tagcd来获得的数组Q所以在for循环中,在重命名checkbox后,safari׃会自动的U除对应的元素。具体代码如下:

        
var elementlist = document.getElementsByTagName("input");
        
var elementSize = elementlist.length;
        
for(var i=0; i<elementSize;i++){
            
var curElement = elementlist[i];
            
if(curElement.type =='checkbox' && curElement.name == 'testCheckbox' && !curElement.checked){
                curElement.name
='testCheckbox-new';
            }
        }



seal 2010-06-11 00:10 发表评论
]]>
prototype.js ?Ajax.updater ?用法(?http://www.aygfsteel.com/sealyu/archive/2010/06/10/323285.htmlsealsealThu, 10 Jun 2010 15:40:00 GMThttp://www.aygfsteel.com/sealyu/archive/2010/06/10/323285.htmlhttp://www.aygfsteel.com/sealyu/comments/323285.htmlhttp://www.aygfsteel.com/sealyu/archive/2010/06/10/323285.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/323285.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/323285.html(container, url, options)
分别表示 1.控gidQ?.h的urlQ?.具体如下Q可选)Q?/font>
属?/th> cd Default 描述
method Array 'post' HTTP h方式。get or post
parameters String '' 在HTTPh中传入的url格式的值列表?/td>
asynchronous Boolean true 指定是否做异?AJAX h?/td>
postBody String undefined 在HTTP POST的情况下Q传入请求体中的内容?/td>
requestHeaders Array undefined 和请求一赯传入的HTTP头部列表Q?q个列表必须含有偶数个项目, M奇数目是自定义的头部的名称Q? 接下来的偶数目使这个头部项目的字符串倹{?例子:['my-header1', 'this is the value', 'my-other-header', 'another value']
onXXXXXXXX Function(XMLHttpRequest) undefined 在AJAXh中,当相应的事g/状态Ş成的时候调用的自定义方法?例如 var myOpts = {onComplete: showResponse, onLoaded: registerLoaded};. q个Ҏ被传入一个参敎ͼ q个参数是携带AJAX操作?XMLHttpRequest对象?/td>
onSuccess Function(XMLHttpRequest) undefined 当AJAXh成功完成的时候调用的自定义方法?q个Ҏ被传入一个参敎ͼ q个参数是携带AJAX操作?XMLHttpRequest对象?/td>
onFailure Function(XMLHttpRequest) undefined 当AJAXh完成但出现错误的时候调用的自定义方法?q个Ҏ被传入一个参敎ͼ q个参数是携带AJAX操作?XMLHttpRequest对象?/td>
insertion Function(Object, String) null Z把返回的文本注入C个元素中而执行的Ҏ?q个Ҏ被传入两个参数Q要被更新的对象q且只应用于 Ajax.Updater 对象中应用?/td>
decay Number undefined, 1 军_当最后一ơ响应和前一ơ响应相同时?function getContents() 

var request_url = "test1.html";       // 需要获取内容的url 
var request_pars = '';//h参数 

var myAjax = new Ajax.Updater('result', request_url,{ // request_urlq回内容l定到id为result的容器中 
method     : 'get'//HTTPh的方?get or post 
parameters : request_pars, //h参数 
onFailure  : reportError, //p|的时候调?nbsp;reportError 函数 
onLoading  : loading, //正在获得内容的时?nbsp;
onComplete : done     //内容获取完毕的时?nbsp;
}); 


function loading() 

$(
'loading').style.display = 'block'


function done() 

$(
'loading').style.display = 'none'


function reportError(request) 

alert(
'Sorry. There was an error.'); 
Ajax.Updater 为我们提供加载文档时候的三种状? onComplete,onLoading,onFailure.我们可以自定义一个函数分别相应这三种不同的状态?br /> 下面的例子用Csuccess (一切OK的时候才被用? Q和它同{地位的属性还有一?font face="Courier New">failure (有地方出问题的时候被用到) q里没用到。出错时?onFailure 处调?reportError Ҏ?br />
<script>
    
function getHTML()
    {
        
var url = 'http://yourserver/app/getSomeHTML';
        
var pars = 'someParameter=ABC';
        
var myAjax = new Ajax.Updater(
                    {success: 
'placeholder'},
                    url,
                    {method: 
'get', parameters: pars, onFailure: reportError});
    }
    
function reportError(request)
    {
        alert(
'Sorry. There was an error.');
    }
</script>

<input type=button value=GetHtml onclick="getHTML()">
<div id="placeholder"></div>


seal 2010-06-10 23:40 发表评论
]]>Detecting Internet Explorer More Effectivelyhttp://www.aygfsteel.com/sealyu/archive/2010/06/09/323114.htmlsealsealTue, 08 Jun 2010 20:35:00 GMThttp://www.aygfsteel.com/sealyu/archive/2010/06/09/323114.htmlhttp://www.aygfsteel.com/sealyu/comments/323114.htmlhttp://www.aygfsteel.com/sealyu/archive/2010/06/09/323114.html#Feedback2http://www.aygfsteel.com/sealyu/comments/commentRss/323114.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/323114.htmlThis topic demonstrates how to detect current and future versions of Windows Internet Explorer more effectively.

This topic contains the following sections.

Introduction

Many Web designers use browser detection techniques to ensure that their sites display properly when viewed with specific browsers. Some browser detection techniques encounter problems when viewed with later versions of the browser they're tailored for. For example, many Web designers used Cascading Style Sheets (CSS) rules that relied on the implementation of CSS in Microsoft Internet Explorer 6 to detect that version of the browser. When Internet Explorer 7 provided additional support for the CSS, Level 2 (CSS2) standard, many of these rules (also known as "CSS hacks") failed to detect the new version of the browser. As a result, sites that relied on these rules no longer displayed as intended. When using browser detection techniques, use techniques that support current and future versions of the browser you're targeting.

This topic examines four different ways to detect Internet Explorer and also provides a brief look at alternatives to browser detection. Advantages of each technique are reviewed and suggestions are offered for effective use. In addition, examples demonstrate techniques that support current and future versions of Internet Explorer.

Parsing the User-Agent String

The most common way to detect Internet Explorer is to use client-side scripting to parse the user-agent string and extract the version number from the version token. The following example shows the preferred way to do this with JavaScript.

function getInternetExplorerVersion()

// Returns the version of Internet Explorer or a -1

// (indicating the use of another browser).

{

var rv = -1; // Return value assumes failure.

if (navigator.appName == 'Microsoft Internet Explorer')

{

var ua = navigator.userAgent;

var re = new RegExp("MSIE ([0-9]{1,}[".0-9]{0,})");

if (re.exec(ua) != null)

rv = parseFloat( RegExp.$1 );

}

return rv;

}

function checkVersion()

{

var msg = "You're not using Internet Explorer.";

var ver = getInternetExplorerVersion();



if ( ver > -1 )

{

if ( ver >= 8.0 )

msg = "You're using a recent copy of Internet Explorer."

else

msg = "You should upgrade your copy of Internet Explorer.";

}

alert( msg );

}

As you review this example, please note the following:

  • A regular expression extracts the version number from the user-agent version token. Regular expressions let you specify optional conditions to match, so that you can match a larger number of version tokens, not just those that match a strict set of conditions.

  • The version number extracted from the version token is formally converted to a numeric value. Care must be taken because pre-release versions of Internet Explorer typically add letters to the version token. For example, the version token for pre-release versions of Internet Explorer 7 was "MSIE 7.0b."

  • The checkVersion() function verifies that the browser is version 8.0 or later. This ensures that the welcome message is displayed for those using newer versions of the browser.

This example properly detects most versions of Internet Explorer, but only if scripting is enabled. However, the user-agent string is dynamic; it can be changed by the end user, by browser extensions, and by operating system updates. As a result, there's no guarantee that the user-agent string accurately reflects the browser being used. The next sections show techniques that may be more effective alternatives.

Note  It is not recommended that you block access to content based on the user-agent string of the browser. If you do have to offer different content to different versions of the browser due to improved capabilities, you want to ensure that future versions of the browser are not blocked. Serving content based solely on the user-agent string is often an unreliable way to detect the full capabilities of the browser.

For more information about the user-agent string and Internet Explorer's user-agent tokens, see Understanding User-Agent Strings.

Using Conditional Comments

If you are specifically interested in Internet Explorer, conditional comments might be a more appropriate choice. The following example shows an effective way to use conditional comments to display custom content.

<!--[if gte IE 8]>

<p>You're using a recent version of Internet Explorer.</p>

<![endif]-->



<!--[if lt IE 7]>

<p>Hm. You should upgrade your copy of Internet Explorer.</p>

<![endif]-->



<![if !IE]>

<p>You're not using Internet Explorer.</p>

<![endif]>

Like the earlier JavaScript example, this example makes sure the current version is greater than or equal to a specified version number. This ensures that the content designed for the current version of the browser is properly displayed in a future version.

This example carefully combines downlevel-revealed and downlevel-hidden conditional comments to ensure that each message appears only for the intended browsers.

Because conditional comments do not rely on JavaScript, they are effective even if the user has disabled scripting. Unlike the user-agent string, conditional comments are typically updated when the browser is upgraded. This makes them more reliable than user-agent strings. However, because no other browser currently supports conditional comments, they are limited to Internet Explorer. Depending on your needs, this may be an advantage or a disadvantage.

For more information about conditional comments, see About Conditional Comments.

Detecting Features

For many Web sites, detecting a browser's features is the preferred form of browser detection because it allow the Web developer to focus on the general capabilities of a browser, rather than the specific details of each browser release. The following example demonstrates a simple form of feature detection.

if (XMLHttpRequest)

{

// This browser implements this feature.

}

Feature detection tends to support a broader range of browsers. In addition, should a browser implement the feature you're interested in, your content will be delivered without requiring changes to your browser detection technique. As a result, techniques that focus on features tend to require less maintenance than techniques that rely on environmental factors, such as the user-agent string. In addition, they tend to work across a wider variety of browser devices, including screen readers, mobile devices, and so on.

Use care when creating or using browser detection techniques that attempt to detect a browser based on unsupported functionality. If a future version of the browser implements the missing feature, it's entirely possible your site may not display as intended.

Using the ASP.NET HttpBrowserCapabilities Object

ASP.NET developers can use the HttpBrowserCapabilities object to detect and respond to almost any browser. In addition, alternate content is not sent to the end-user's browser. The following example shows how to detect Internet Explorer from an ASP.NET application using C#.

private float getInternetExplorerVersion()

{

// Returns the version of Internet Explorer or a -1

// (indicating the use of another browser).

float rv = -1;

System.Web.HttpBrowserCapabilities browser = Request.Browser;

if (browser.Browser == "IE")

rv = (float)(browser.MajorVersion + browser.MinorVersion);

return rv;

}



private void Page_Load(object sender, System.EventArgs e)

{

string msg;

double ver = getInternetExplorerVersion();

if (ver > 0.0)

{

if (ver >= 7.0)

msg = "You're using a recent version of Internet Explorer.";

else

msg = "You should upgrade your copy of Internet Explorer.";

}

else

msg = "You're not using Internet Explorer.";



Label1.Text = msg;

}

Because the HttpBrowserCapabilities object parses the user-agent string for you, you can use the MajorVersion and MinorVersion properties to determine the current version of the browser. Unlike the JavaScript examples, these properties are numeric; MajorVersion returns an integer value, and MinorVersion returns a double value. Depending on the language used to implement your ASP.NET application, however, you might still have to typecast these property values to the data type you're using. To illustrate, the C# example converts MajorValue to the floating point value returned by the function.

For more information about the HttpBrowserCapabilities object, see HOW TO: Determine the Browser Version in ASP.NET or Browser Sniffing in ASP.NET World Wide Web link.

Alternatives to Browser Detection

If you use browser detection because Internet Explorer doesn't appear to support a particular feature, an alternate approach may be more effective. Before implementing new (or revising existing) browser detection, it may be worthwhile to consider one of the following approaches to solve the underlying problem.

  • Internet Explorer allows Web developers to choose between various document compatibility modes that affect the way the browser interprets and displays content. If you are not seeing the results you expect, a different document compatibility mode may provide the results you seek. For more information, see Defining Document Compatibility.

    You may want to consider using the Developer Tools to preview your pages in different document compatibility modes or to experiment with different ways to achieve various visual and layout effects. It's entirely possible there's another way to accomplish the same result.

  • If the Document Object Model (DOM) doesn't support a feature that you need, you may be able to add the feature using DOM mutable prototypes.

  • If none of the previous suggestions apply, it may be worthwhile to consider using an alternate approach.

Summary

If you must detect the browsers that view your Web sites, follow effective practices: plan for future browser releases, convert values appropriately, and design techniques to fail gracefully. Doing so will reduce the long-term maintenance of your site and help ensure that your site functions properly when viewed with newer versions of Internet Explorer and other browsers.

Community Content
Annotations
Bad browser detection
Using "v to detect IE is a bad idea because this will not work if future versions of IE change this behavior. The officially supported detection methods should be used.

However this example from the article is misleading. Since other browsers don't support conditional comments [if !IE] results in comments that will show up in no browsers.
<![if !IE]>
<p>You're not using Internet Explorer.</p>
<![endif]>

How to detect IE8 using JavaScript
Check out:
http://blogs.msdn.com/giorgio/archive/2009/04/14/how-to-detect-ie8-using-javascript-client-side.aspx

Shortest way of detecting IE

More efficient way to detect any version of IE is

function isMSIE() {

return '"v' == 'v';

}


The JScript engine used in IE doesn't recognize and therefore escape vertical tabulation character while all other does.



seal 2010-06-09 04:35 发表评论
]]>
Using the navigator object to detect client's browserhttp://www.aygfsteel.com/sealyu/archive/2010/06/09/323113.htmlsealsealTue, 08 Jun 2010 20:34:00 GMThttp://www.aygfsteel.com/sealyu/archive/2010/06/09/323113.htmlhttp://www.aygfsteel.com/sealyu/comments/323113.htmlhttp://www.aygfsteel.com/sealyu/archive/2010/06/09/323113.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/323113.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/323113.html Until one browser remains standing on the web (if ever), browser detection will continue to be part of any good JavaScripter's life. Whether you're gliding a div across the screen or creating an image rollover, it's fundamental that only relevant browsers pick up on your code. In this tutorial we'll probe the navigator object of JavaScript, and show how to use it to perform browser detection, whether the subject is Firefox, Internet Explorer 7, Opera, etc.

The navigator object

The navigator object was conceived back in the days when Netscape Navigator reined supreme. These days it serves as much as an irony of NS's diminished market share as way of probing browser information.

The navigator object of JavaScript contains the following core properties:

Properties Description
appCodeName The code name of the browser.
appName The name of the browser (ie: Microsoft Internet Explorer).
appVersion Version information for the browser (ie: 4.75 [en] (Win98; U)).
cookieEnabled Boolean that indicates whether the browser has cookies enabled.
language Returns the default language of the browser version (ie: en-US). NS and Firefox only.
mimeTypes[] An array of all MIME types supported by the client. NS and Firefox only.
platform[] The platform of the client's computer (ie: Win32).
plugins An array of all plug-ins currently installed on the client. NS and Firefox only.
systemLanguage Returns the default language of the operating system (ie: en-us). IE only.
userAgent String passed by browser as user-agent header. (ie: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1))
userLanguage Returns the preferred language setting of the user (ie: en-ca). IE only.

Let's see exactly what these properties reveal of the browser you're currently using:

appCodeName: Mozilla
appName: Netscape
appVersion: 5.0 (Windows; zh-CN)
userAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
platform: Win32

At a glance

At a glance at the above table, you may be swayed towards turning to the following two properties to do your browser detection bidding:

navigator.appName
navigator.appVersion

After all, you are trying to detect a browser's name and version right? However, they both will most likely mislead you. In browsers such as various versions of Netscape and Firefox, these two properties return simply "Netscape" for appName, and 5.0 for appVersion without any further distinction for Firefox and its version, and hence are pretty much useless in the real world. For example, in both Firefox 1.x and Firefox 2.x, these two properties return:

appName: Netscape

appVersion: 5.0 (Windows; en-US)

We need to turn to a property that's more thorough in its investigative work if we want more consistency and accuracy, and that turns out to be navigator.userAgent.

Detecting Firefox x.x

In Firefox 2.0.0.13 for example, the userAgent property reads:

UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13

The detail we're interested in apparently lies at the very end, or Firefox/2.0.0.13. Different versions of Firefox will contain a different version number, but the pattern is consistent enough. The part we're interested in occurs after the string "Firefox/", or the exact version number. There are many ways to get to it using either standard String or RegExp methods- I'm opting for the later here:

<script type="text/javascript">

if (/Firefox["/"s]("d+"."d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
 var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ffversion>=3)
  document.write("You're using FF 3.x or above")
 else if (ffversion>=2)
  document.write("You're using FF 2.x")
 else if (ffversion>=1)
  document.write("You're using FF 1.x")
}
else
 document.write("n/a")

</script>

Output: You're using FF 3.x or above

Basically, I'm capturing just the versonMajor.versionMinor portion of the full version number of Firefox (ie: 2.0.0.13 becomes simply 2.0), and using that as basis to detect the various versions of Firefox. Delving any deeper, and the returned version may no longer be a number but a string (ie: 2.0.0), which makes numeric comparisons cumbersome.

Detecting IE x.x

In IE 7.0 for example, the userAgent property reads:

UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)

So the part we're interested in lies in the middle, or MSIE 7.0;. If you try a shortcut and use parseFloat on the entire string to get to the 7.0 portion, it won't work. This is due to the way parseFloat works- by returning the first number it encounters, which in this case is 4.0. Once again we need to use either standard String or RegExp methods again to get to the actual version number; below I'm using RegExp as well:

<script type="text/javascript">



if (/MSIE ("d+"."d+);/.test(navigator.userAgent)){ //test for MSIE x.x;

 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number

 if (ieversion>=8)

  document.write("You're using IE8 or above")

 else if (ieversion>=7)

  document.write("You're using IE7.x")

 else if (ieversion>=6)

  document.write("You're using IE6.x")

 else if (ieversion>=5)

  document.write("You're using IE5.x")

}

else

 document.write("n/a")

</script>

Output: n/a

Detecting Opera x.x

Detecting Opera using the navigator object at first appears to be tricky business due to the browser's identity crisis. You see, Opera 8 and below by default identifies itself as IE6 (or lower) in the navigator object. Users can override this setting under "Edit Site Settings" in the toolbar to identify as Opera or even another browser instead. Starting in Opera 9, the browser regains its confidence and identifies by default as itself, Opera, though users can still modify this setting manually in the toolbar. The bottom line is, Opera can appear as either Opera, Internet Explorer, or another browser within a designated list in the navigator object.

Lets take a look at what navigator.userAgent in Opera 8.5 returns depending on what it has chosen to identify itself as (whether automatically or manually):

As IE6: Mozilla/4.0 (compatible; MSIE 6.0; Windows XP) Opera 8.5 [en]
As Moz5: Mozilla/5.0 (Windows XP; U) Opera 8.5 [en]
As Opera: Opera/8.5 (Windows XP; U) [en]

Notice how if it's set to identify as IE, MSIE 6.0 appears within the string, while if set to identify as Mozilla, Mozilla/5.0 appears instead. As Opera itself, Opera/8.5 appears. In all three cases, the one commonality that we can exploit to actually detect Opera and its true version regardless of which identify it's decided to take on is the string "Opera x.x" or "Opera/x.x" within navigator.userAgent. In other words, there are two versions of the target string we need to be aware of. With that said, here's how you might go about testing for a specific version of Opera, which turns out to be no different than the technique used for detecting, say, Firefox:

<script type="text/javascript">
//Note: userAgent in Opera9.24 WinXP returns: Opera/9.24 (Windows NT 5.1; U; en)
//         userAgent in Opera 8.5 (identified as IE) returns: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 8.50 [en]
//         userAgent in Opera 8.5 (identified as Opera) returns: Opera/8.50 (Windows NT 5.1; U) [en]

if (/Opera["/"s]("d+"."d+)/.test(navigator.userAgent)){ //test for Opera/x.x or Opera x.x (ignoring remaining decimal places);
 var oprversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (oprversion>=10)
  document.write("You're using Opera 10.x or above")
 else if (oprversion>=9)
  document.write("You're using Opera 9.x")
 else if (oprversion>=8)
  document.write("You're using Opera 8.x")
 else if (oprversion>=7)
  document.write("You're using Opera 7.x")
 else
  document.write("n/a")
}
else
 document.write("n/a")
</script>

Output: n/a

Conclusion

We've seen how to use navigator to detect the browser type of your visitors. If the potential pitfalls and complexity of usage of it is a little too much for you, an alternative is to use Object Detection. Whichever method you choose, just be sure to choose one!



seal 2010-06-09 04:34 发表评论
]]>
IE ?Firefox中取得createRange()的v点和l点的?/title><link>http://www.aygfsteel.com/sealyu/archive/2010/06/08/323099.html</link><dc:creator>seal</dc:creator><author>seal</author><pubDate>Tue, 08 Jun 2010 14:23:00 GMT</pubDate><guid>http://www.aygfsteel.com/sealyu/archive/2010/06/08/323099.html</guid><wfw:comment>http://www.aygfsteel.com/sealyu/comments/323099.html</wfw:comment><comments>http://www.aygfsteel.com/sealyu/archive/2010/06/08/323099.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sealyu/comments/commentRss/323099.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sealyu/services/trackbacks/323099.html</trackback:ping><description><![CDATA[<html><br /> <head><br /> <title>TEST</title><br /> <style><br /> body,td{<br />     font-family: verdana, arial, helvetica, sans-serif;<br />     font-size: 12px;<br /> }<br /> </style><br /> <script type="text/javascript"><br />     var start=0;<br />     var end=0;<br />     function add(){       <br />         var textBox = document.getElementById("ta");<br />         var pre = textBox.value.substr(0, start);<br />         var post = textBox.value.substr(end);<br />         textBox.value = pre + document.getElementById("inputtext").value + post;<br />     }<br />     function savePos(textBox){<br />         //如果是Firefox(1.5)的话Q方法很?br />         if(typeof(textBox.selectionStart) == "number"){<br />             start = textBox.selectionStart;<br />             end = textBox.selectionEnd;<br />         }<br />         //下面是IE(6.0)的方法,ȝ得很Q还要计上'"n'<br />         else if(document.selection){<br />             var range = document.selection.createRange();<br />             if(range.parentElement().id == textBox.id){<br />                 // create a selection of the whole textarea<br />                 var range_all = document.body.createTextRange();<br />                 range_all.moveToElementText(textBox);<br />                 //两个rangeQ一个是已经选择的text(range)Q一个是整个textarea(range_all)<br />                 //range_all.compareEndPoints()比较两个端点Q如果range_all比range更往?further to the left)Q则                //q回于0的|则range_all往右移一点,直到两个range的start相同?br />                 // calculate selection start point by moving beginning of range_all to beginning of range<br />                 for (start=0; range_all.compareEndPoints("StartToStart", range) < 0; start++)<br />                     range_all.moveStart('character', 1);<br />                 // get number of line breaks from textarea start to selection start and add them to start<br />                 // 计算一?n<br />                 for (var i = 0; i <= start; i ++){<br />                     if (textBox.value.charAt(i) == '\n')<br />                         start++;<br />                 }<br />                 // create a selection of the whole textarea<br />                  var range_all = document.body.createTextRange();<br />                  range_all.moveToElementText(textBox);<br />                  // calculate selection end point by moving beginning of range_all to end of range<br />                  for (end = 0; range_all.compareEndPoints('StartToEnd', range) < 0; end ++)<br />                      range_all.moveStart('character', 1);<br />                      // get number of line breaks from textarea start to selection end and add them to end<br />                      for (var i = 0; i <= end; i ++){<br />                          if (textBox.value.charAt(i) == '\n')<br />                              end ++;<br />                      }<br />                 }<br />             }<br />         document.getElementById("start").value = start;<br />         document.getElementById("end").value = end;<br />     }<br /> </script><br /> </head><br /> <body><br /> <form action="a.cgi"><br /> <table border="1" cellspacing="0" cellpadding="0"><br />     <tr><br />         <td>start: <input type="text" id="start" size="3"/></td><br />         <td>end: <input type="text" id="end" size="3"/></td><br />     </tr><br />     <tr><br />         <td colspan="2"><br />             <textarea id="ta" onKeydown="savePos(this)"<br />                               onKeyup="savePos(this)"<br />                               onmousedown="savePos(this)"<br />                               onmouseup="savePos(this)"<br />                               onfocus="savePos(this)"<br />                               rows="14" cols="50"></textarea><br />         </td><br />     </tr><br />     <tr><br />         <td><input type="text" id="inputtext" /></td><br />         <td><input type="button" onClick="add()" value="Add Text"/></td><br />     </tr><br /> </table><br /> </form><br /> </body><br /> </html><br /> <br /> 附:IE 中的定义Q?http://msdn.microsoft.com/en-us/library/ms535872%28VS.85%29.aspx<br /> http://msdn.microsoft.com/en-us/library/ms533042%28VS.85%29.aspx<br /> <img src ="http://www.aygfsteel.com/sealyu/aggbug/323099.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sealyu/" target="_blank">seal</a> 2010-06-08 22:23 <a href="http://www.aygfsteel.com/sealyu/archive/2010/06/08/323099.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Setting the name attribute in IE's DOMhttp://www.aygfsteel.com/sealyu/archive/2010/06/04/322693.htmlsealsealThu, 03 Jun 2010 22:04:00 GMThttp://www.aygfsteel.com/sealyu/archive/2010/06/04/322693.htmlhttp://www.aygfsteel.com/sealyu/comments/322693.htmlhttp://www.aygfsteel.com/sealyu/archive/2010/06/04/322693.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/322693.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/322693.htmlAn old problem with IE is that you can't set the name attribute on form elements in the DOM directly. Fortunately there is a workaround to this issue using IE's mergeAttributes method. By creating a temporary named element acceptable by IE's createElement method, you can merge the name attribute into the element you desire, allowing you to name or rename an element. An example demo follows.

var setName = function(el, newName) {

el = (typeof el === "string") ? document.getElementById(el) : el;

el.name = newName;

if (/*@cc_on!@*/0) { // Internet Explorer test (needs to be modified for IE8)

el.mergeAttributes(document.createElement("<INPUT name='" + newName + "'/>"), false);

}

};

In Mootools 1.2.1:

var setName = function(elementId, newName) {

var el = (!!elementId) ? $(elementId) : null;

if (!elementId || !newName || !el) return;



el.set({ "name" : newName });

if (Browser.Engine.trident4 || Browser.Engine.trident5) {

el.mergeAttributes(document.createElement("<INPUT name='" + newName + "'/>"), false);

}

};

Demo:

Before OUTERHTML:

<INPUT id=renameTarget value="Set Random Name" type=submit>


seal 2010-06-04 06:04 发表评论
]]>
Inserting at the cursor using JavaScripthttp://www.aygfsteel.com/sealyu/archive/2010/06/04/322689.htmlsealsealThu, 03 Jun 2010 19:12:00 GMThttp://www.aygfsteel.com/sealyu/archive/2010/06/04/322689.htmlhttp://www.aygfsteel.com/sealyu/comments/322689.htmlhttp://www.aygfsteel.com/sealyu/archive/2010/06/04/322689.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/322689.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/322689.htmlNOTE: I’ve released a set of JavaScript Quicktags (that implement this technique) under the LGPL license. Please look at this code as it has a variety of enhancements and bug fixes.

I discovered a real JavaScript gem in PHPMyAdmin this morning. They have code that inserts content into a <textarea> at the cursor position instead of just at the beginning/end of the content. This is something I thought wasn’t possible – I’m quite pleased I was wrong.

I’ll be glad to see this code spread quickly to web forms that use buttons to aid in styling text and inserting image and link tags. WordPress and other blog and web forum packages would really benefit from this. (PHPMyAdmin is GPL, so any other GPL app should be able to use their code directly with attribution).

Here is a quick look at a generic version of the technique:

function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}
// calling the function
insertAtCursor(document.formName.fieldName, 'this value');
I guess when the mouse leaves the textarea, it still has a cursor position left over. This code uses that position just as you’d want it to.

seal 2010-06-04 03:12 发表评论
]]>
15个用jQuery实现囄qȝ片效果的JS源码(?http://www.aygfsteel.com/sealyu/archive/2010/05/18/321222.htmlsealsealMon, 17 May 2010 18:02:00 GMThttp://www.aygfsteel.com/sealyu/archive/2010/05/18/321222.htmlhttp://www.aygfsteel.com/sealyu/comments/321222.htmlhttp://www.aygfsteel.com/sealyu/archive/2010/05/18/321222.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/321222.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/321222.htmljQuery作ؓ一个应用最q泛的JavaScript框架之一Q第三方开发者不断地为其开发出新的 jQuery 插g应用Q从而得jQuery可以帮助用户实现各种各样不同d?Web 效果Q作为最怋用的囄qȝ片效果更是jQuery的强,看完本文Z整理推荐?5个优U的jQuery囄qȝ?d效果Q你会收h多?/p>

15个优U的jQuery囄qȝ?d效果Q基本都已经包含了原插g的发布地址、用方法和源代码下载?/p>

1QGallerific

Galleriffic 是? Mike Alsup ?jQuery Cycle plugin 创徏的图片展C效果,包括~略图、图片标题和描述{详l功能,是一个非怸错的高质量画廊相册展C工兗?/p>

2QZoomImage

zoomimage Q以一U独具魅力的方式展示囄效果。羃略图链接在本弹出大图,q且可以可以随意拖拽该悬图片?/p>

3QEasySlider

Easy Slider 可以实现囄或其他Q意内容,在水qx垂直方向上的滑动效果Q你q可以通过 CSS 自定义设|样式?/p>

4QThe Slider from Barack Obama’s website

一个源自美国ȝ Barack Obama |站的垂下滑动菜单控制的囄qȝ效果?/p>

5QCodaSlider

CodaSliderQ? 又一个不错的滑动控制效果?/p>

6QjQuery Slider II

jQuery Slider II 的布局非常W合操作习惯Q在底部列出带滚动条的羃略图控制列表Q然后在上面昄对应囄的大图浏览,非常适合做高U相册?/p>

7QBeautiful Slider

Beautiful SliderQ? 光看q个效果图你q道这个插件有多棒了吧Q是的,q个插g实现的效果已l不逊色于Flash完成的效果,整体表现畅Q文字显C效果更是创意独牏V?/p>

Q,LoopedSlider

loopedSlider是又一个Q意内Ҏ? 切换的灯片插gQ用操作简单?/p>

9QSpaceGallery

Accessible news slider

SpaceGallery是一个全新的jQuery插gQ点d 前图片,会自动放大消失,同时后面的图片向前展C,有一U时光机器的感觉?/p>

10QjQuery Popeye

11QNoobslide

Noobslide

12QAccessible News Slider

Accessible news slider

13QSmoothGallery

SmoothGallery

SmoothGallery是一个最好的 Javascript qȝ片效果之一Q可以实现各U不同的qȝ片{换效果?/p>

14QjQuery Multimedia Portfolio

jQuery Multimedia Portfolio

jQuery Multimedia Portfolio是一个基于jQuery 的滑动效果插?除了可以展示囄之外Q还可以加入各种不同cd的多媒体文g?/p>

15Qs3Slider

s3Slider是一个非常简单实用的畅qȝ片效果,q个 插g被应用在无数的WordPress专业主题模板中?/p>

seal 2010-05-18 02:02 发表评论
]]>
javascript 字符串处理全ȝ(?http://www.aygfsteel.com/sealyu/archive/2010/04/15/318462.htmlsealsealThu, 15 Apr 2010 15:47:00 GMThttp://www.aygfsteel.com/sealyu/archive/2010/04/15/318462.htmlhttp://www.aygfsteel.com/sealyu/comments/318462.htmlhttp://www.aygfsteel.com/sealyu/archive/2010/04/15/318462.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/318462.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/318462.html

javascript 字符串处?/strong>

文章来源Q?a target="_blank">http://lmgq.vip.sina.com/tech/jsadvancedlesson/c2p1.htm

一、声明字W串:
var normal_monkey = "I am a monkey!<br>";
document.writeln("Normal monkey " + normal_monkey);

var bold_monkey = normal_monkey.bold();
document.writeln("Bold monkey " + bold_monkey);

q里的声明: var bold_monkey = normal_monkey.bold();
和下面对声明是等同的Q?nbsp;
var bold_monkey = "<b>" + normal_monkey + "</b>";

W?个版本的声明看v来要明得多。这里用C字符串对象中
的bold对象Q其他的字符串对象还有indexOf, charAt, 
substring, 以及split, q些Ҏ可以深入字符串的l成l构?br /> 首先我们研究一下indexOf?/p>

2、indexOf
indexOf用于发现一pd的字W在一个字W串中等位置q告诉你子字W串的v始位|。如

果一个字W串中部包含该子字符串则indexOfq回returns "-1."
例子Q?br /> var the_word = "monkey"; 
 //让我们从单词 "monkey"开始?nbsp;
var location_of_m = the_word.indexOf("m"); 
 //location_of_m(字母m的位|?ؓ0Q因为字母m位于该字W串的v始位|?br /> var location_of_o = the_word.indexOf("o"); 
 //location_of_o(字母o的位|?ؓ1?br /> var location_of_key = the_word.indexOf("key"); 
 //location_of_key(key的位|?ؓ3因ؓ子字W串“key”以字母k开始,而k

在单词monkey中的位置??br /> var location_of_y = the_word.indexOf("y"); 
 //location_of_y)字母y的位|???nbsp;
var cheeky = the_word.indexOf("q"); 
 //cheeky值是-1Q因为在单词“monkey”中没有字母q?/p>

indexOf更实用之?
var the_email = prompt("What’s your email address?", "");
var the_at_is_at = the_email.indexOf("@");
if (the_at_is_at == -1)
{
    alert("You loser, email addresses must 
    have @ signs in them.");
}

q段代码询问用户的电子邮件地址Q如果用戯入的电子邮g地址中不包含字符 ?nbsp;?/p>

C用PQ你输入的电子邮件地址无效Q电子邮件的地址必须包含字符@。"

3、charAt 
chatAtҎ用于发现一个字W串中某个特定位|的字符?br /> q里是一个例子:
var the_word = "monkey";
var the_first_letter = the_word.charAt(0);
var the_second_letter = the_word.charAt(1);
var the_last_letter = the_word.charAt(the_word.length-1);

the_first_letter(W?个字W??m"
the_second_letter(W?个字W??o"
the_last_letter(最后一个字W??nbsp;"y"

注意利用字符串的length(长度)属性你可以发现在包含多个字符。在本例中,

the_word?monkey"Q所以the_word.length?。不要忘记在一个字W串中第1个字W的

位置?Q所以最后一个字W的位置是length-1。所以在最后一行中用了

the_word.length-1?gt;>

4、子字符ԌsubstringQ?br /> 子字W串QsubstringQ和charAt有些象,不同之处在于它能够从一个单词中抓取整个?/p>

子字W串Q而不只是字母Q这里是其格式:

var the_substring = the_string.substring(from, to);

"From"指的是子字符串中W1个字母的位置Q?to"有点奇特Q它是该子字W串中比最?/p>

一个位|大Q的位置Q用这U神奇的Ҏ你可以标记子字符串的起始和结束位|,?/p>

"to"的位|减?from"的位|就会得子字W串的长度:

var the_string = "monkey";
var clergy = the_string.substring(0,4);
var tool = the_string.substring(3,6);

q行该段代码后变量clergy的gؓ"monk"; 变量tool的gؓ"key"?/p>

子字W串常和indexOf一起用,字W串分成若干块.例如Q?br /> 你可以从一个给定的URL中抽取出其域名:

var the_url = prompt("What’s the URL?","");
var lead_slashes = the_url.indexOf("http://");
var domain_start = lead_slashes + 2;
var without_resource = the_url.substring(domain_start, the_url.length);
var next_slash = without_resource.indexOf("/");
var domain = without_resource.substring(0, next_slash);

q段代码的意思是Q如果你输入
"http://www.webmonkey.com/javascript/index.html";Q则域名 是

"www.webmonkey.com" Q如果这个方法对你来说有些麻烦,我将向你介绍如何使用split

Ҏ化其执行q程Q但是首先我们作一些分析.

基本的技巧是第Q个斜杠和第Q个斜杠之间的内容分d来:
var the_url = prompt("What’s the URL?",""); 
//q行代码向用戯问一个URLQ假讄戯入了
"http://www.webmonkey.com/javascript/index.html."
var lead_slashes = the_url.indexOf("http://"); 
q行代码定W一个双斜杠的位|.在本例中lead_slashes的值是Q,因ؓ双斜杠的?/p>

|从Q开始.

你可能会惻I通常的URL都是以http://开始,所以双斜杠的位|肯定是在5开始,Z

么还要加入indexOfq一D多余的代码呢?但是问题的关键在于你不知道用户在填入URL

时是否一定填入http:Q他们也怼不小心多键入了一个空|也许他们所键入的URL?/p>

一个加密服务器上,其URL?https://www.whatever.com/"; Q? 在编E你必须预料到种U?/p>

可能发生的问题.所以我们必ȝindexOfҎ定双斜杠的切的v始位|.

var domain_start = lead_slashes + 2; 

q行代码用于计算该域名的W1个字母的起始位置Q由于这里有一个双斜杠Q所以域?/p>

W1个字母的起始位置应该在双斜杠所在位|加Q的位置Q?/p>

var without_resource = the_url.substring(domain_start, the_string.length); 

q段代码域名v始位|往后的所有字W都提取出来Q所以执行完q行代码?/p>

without_resource?www.webmonkey.com/javascript/index.html." 

var next_slash = without_resource.indexOf("/"); 

q行代码计算字符串中下一个斜杠的位置Q而从该字W串起始位置到这个斜杠之?/p>

的内容就是域名.在本例中下一个斜杠的位置?7?/p>

var domain = without_resource.substring(0, next_slash); 

最后一步是提取字符串v始位|到下一个斜杠之间的所有内容.在本例中使得域名

{同?www.webmonkey.com"?/p>

q样做确实很ȝQ利用splitҎ则可以该过E容易很多.>>

5、分割方?splitting method) 
你可以用splitҎ用限位器来分割一pd的名Uͼ然后其
攑֜一个数l中Q例如:

var my_friends ="trixie,moxie,sven,guido,hermes";

var friend_array =my_friends.split(",");

for (loop=0; loop < friend_array.length;loop++)
{    document.writeln(friend_array[loop] + " is myfriend.<br>");}

q段代码字W串my_friends分割成包含5个元素的数组QJavaScript可以Z自动?/p>

立一个数l,所以你无需使用new Array()Q?/p>

字W串分割成数l之后,我们使用了@环语句写出每一个名Uͼ我们可以利用split?/p>

法简化前面所讲到的域名提取:

var the_url = prompt("What’s the URL?","");
var first_split = the_url.split("http://");
var without_resource = first_split[1];
var second_split = without_resource.split("/");
var domain = second_split[0];

q段代码化了很多而且也更Ҏ理解Q我们来分析一些这D代码:

var the_url = prompt("What’s the URL?",""); 

提示用户输入一个URLQ假讄戯?br /> "http://www.webmonkey.com/javascript/index.html"; Q?br /> var first_split = the_url.split("http://"); 
用戯入的字符串分割成两块Qfirst_split[0]?http:"Qfirst_split[1]?/p>

"www.webmonkey.com/javascript/index.html." 
var without_resource = first_split[1]; 
//提取出数l中的第Q个元素Q所以现在without_resource?/p>

"www.webmonkey.com/javascript/index.html." 
var second_split = without_resource.split("/"); 
without_resource分割成3块:www.webmonkey.com,javascript, 和index.htmlQ现

在你可以看到split的用途了吧?

var domain = second_split[0]; 

现在我们提取出新数组中的W1个元素就可得出域名.



seal 2010-04-15 23:47 发表评论
]]>
Javascript: setTimeout()使用?setInterval()使用http://www.aygfsteel.com/sealyu/archive/2009/12/24/307165.htmlsealsealThu, 24 Dec 2009 07:43:00 GMThttp://www.aygfsteel.com/sealyu/archive/2009/12/24/307165.htmlhttp://www.aygfsteel.com/sealyu/comments/307165.htmlhttp://www.aygfsteel.com/sealyu/archive/2009/12/24/307165.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/307165.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/307165.html

Evaluates an expression after a specified number of milliseconds has elapsed.

(在指定时间过后执行指定的表达?


Syntax:

iTimerID = window.setTimeout(vCode, iMilliSeconds [, sLanguage])

Parameters

vCode Required. Variant that specifies the function pointer or string that indicates the code to be executed when the specified interval has elapsed.
iMilliSeconds Required. Integer that specifies the number of milliseconds.
sLanguage Optional. String that specifies one of the following values:
JScript Language is JScript.
VBScript Language is VBScript.
JavaScript Language is JavaScript.

Return Value

Integer. Returns an identifier that cancels the evaluation with the clearTimeout method.

==============================================================

以上内容摘自某本JScript教程(CHM格式,出处不详,跟原作者说声Sorry)


以下内容没抄M人的,如果有雷?估计不是你抄偶的是巧合,嘿嘿.

-------------------------------------------------------------------
setTimeout( alert("3U种q去?), 3000);//调用一个函?允许带常量参?br /> -------------------------------------------------------------------
<script language="Javascript">
//by zuoyang

var x = 1;
var y = 2;
var z = 3;

var sum;

function Plus(a, b)
{
          var z = 0;
          var i = 0;
          for (i = 0; i < arguments.length; i++)
          {
                   z += arguments[i];
          }
          setTimeout( function() {alert(z);}, 6000); //可以带变量参数的setTimeout调用形式
          return z;
}

setTimeout( function(){ sum = Plus(x, y, z); }, 3000);/*除了可以带变量参数还可以获取q回值的setTimeout调用形式*/

</script>

setInterval()的用法和setTimeout()是一L:

iTimerID = window.setInterval(vCode, iMilliSeconds [, sLanguage])

不同的是setTimeout()是一ơ性作?而setInterval()是每?em>iMilliSeconds执行一?em>vCode.(Evaluates an expression each time a specified number of milliseconds has elapsed)



seal 2009-12-24 15:43 发表评论
]]>
javascript CDATA的意?http://www.aygfsteel.com/sealyu/archive/2009/12/07/304961.htmlsealsealMon, 07 Dec 2009 02:04:00 GMThttp://www.aygfsteel.com/sealyu/archive/2009/12/07/304961.htmlhttp://www.aygfsteel.com/sealyu/comments/304961.htmlhttp://www.aygfsteel.com/sealyu/archive/2009/12/07/304961.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/304961.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/304961.htmlCDATA 内部的所有东襉K会被解析器忽略?/p>

假如文本中包含了大量?"<" ?"&" 字符 - 像~程代码中经常出现的情况一?- 那么q个 XML 元素可以被定义Z?CDATA 部分?/p>

CDATA 区段开始于 "<![CDATA["Q结束于 "]]>"Q?/p>

<script type="text/javascript">
<![CDATA[
function compare(a,b)
{
if (a < b)
   {alert("a于b");}
else if (a>b)
   {alert("a大于b");}
else
   {alert("a{于b");}
}
]]>
</script>

在上面的例子中,?CDATA 区段中的所有东襉K会被解析器忽略?/p>


关于 CDATA 区段的注?

CDATA 区段不能包含字符?"]]>"Q所以,CDATA 区段的嵌套是不被允许的?/p>

同时也需要确保在 "]]>" 字符串中没有I格或折行?/p>

Z么要使用CDATA:

       XHTML的第二个改变是用CDATADcXML中的CDATAD는于声明不应被解析为标{文本QXHTML也是如此Q,q样可以用特D字W,? 于Q?lt;Q、大于(>Q、和P&Q和双引P"Q,而不必用它们的字符实体。考虑下面的代码:

<script type="text/javascript">
function compare(a,b)
{
if (a < b)
   {alert("a于b");}
else if (a>b)
   {alert("a大于b");}
else
   {alert("a{于b");}
}
</script>

q个函数相当单,它比较数字a和bQ然后显C消息说明它们的关系。但是,在XHTML中,q段代码是无效的Q因为它使用了三个特D符P卛_于? 大于和双引号。要修正q个问题Q必d别用q三个字W的XML实体&lt;?amp;gt;?amp;quot;替换它们Q?/p>

<script type="text/javascript">
function compare(a,b)
{
if (a &lt;b)
   {alert(&quot;a于b&quot;);}  
else if (a&gt;b)
   {alert(&quot;a大于b&quot;);}
else
   {alert(&quot;a{于b&quot;);}
}
</script>

q段代码存在两个问题。首先,开发者不习惯用XML实体~写代码。这使代码很难读懂。其ơ,在JavaScript中,q种代码实际上将视ؓ有语? 错,因ؓ解释E序不知道XML实体的意思。用CDATAD即可以以常规Ş式(xȝ语法Q编写JavaScript代码。正式加入CDATAD늚Ҏ? 下:

<script type="text/javascript">
<![CDATA[
function compare(a,b)
{
if (a < b)
   {alert("a于b");}
else if (a>b)
   {alert("a大于b");}
else
   {alert("a{于b");}
}
]]>
</script>

虽然q是正式方式Q但q要CQ大多数览器都不完全支持XHTMLQ这带来主要问题,卌在JavaScript中是个语法错误,因ؓ大多数浏览器q不认识CDATADc?/p>

<script type="text/javascript">
//<![CDATA[                                            
function compare(a,b)
{
if (a < b)
   {alert("a于b");}
else if (a>b)
   {alert("a大于b");}
else
   {alert("a{于b");}
}
//]]>                                      
</script>

当前使用的解x案模仿了“Ҏ览器隐?#8221;代码的方法。用单行的JavaScript注释"http://"Q可在不影响代码语法的情况下嵌入CDATAD:

现在Q这D代码在不支持XHTML的浏览器中也可运行?/p>

但是Qؓ避免CDATA的问题,最好还是用外部文g引入JavaScript代码?/p>

seal 2009-12-07 10:04 发表评论
]]>
深入认识javascript中的eval函数(?http://www.aygfsteel.com/sealyu/archive/2009/05/19/271465.htmlsealsealTue, 19 May 2009 02:10:00 GMThttp://www.aygfsteel.com/sealyu/archive/2009/05/19/271465.htmlhttp://www.aygfsteel.com/sealyu/comments/271465.htmlhttp://www.aygfsteel.com/sealyu/archive/2009/05/19/271465.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/271465.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/271465.html Q?Q介ljavascript中的eval函数的用?br /> Q?Q如何在函数内执行全局代码
►先来说eval的用法,内容比较单,熟悉的可以蟩q?br /> eval函数接收一个参数sQ如果s不是字符Ԍ则直接返回s。否则执行s语句。如果s语句执行l果是一个|则返回此|否则q回undefined?br /> 需要特别注意的是对象声明语?#8220;{}”q不能返回一个|需要用括号括v来才会返回|单示例如下:
var code1='"a" + 2';    //表达?br /> var code2='{a:2}';      //语句
alert(eval(code1));     
//->'a2'
alert(eval(code2));     
//->undefined
alert(eval('(' + code2 + ')'));    //->[object Object]
        可以看到Q对于对象声明语句来_仅仅是执行,q不能返回倹{ؓ了返回常用的“{}”q样的对象声明语句,必须用括h住,以将其{换ؓ表达式,才能q回其倹{这也是使用JSON来进行Ajax开发的基本原理之一。在例子中可以清楚的看到Q第二个alert语句输出的是undefinedQ而第三个加了括号后输出的是语句表C的对象?/div>
            ►现在来说本文的重点Q如何在函数内执行全局代码。ؓ了说明这个问题,先看一个例子:
var s='global';    //定义一个全局变量
function demo1(){
    eval('var s="local"');
}
demo1();
alert(s);    //->global
         很好理解Q上面的demo1函数{h于:function demo1(){var s='local';}Q其中定义了一个局部变量s?br />         所以最后的输出是globalq不是什么奇怪的事情Q毕竟大安能很清楚的区分局部变量和全局变量?br />         仔细体会一下,可以发现eval函数的特点,它L在调用它的上下文变量I间Q也UCؓQ包QclosureQ内执行Q无论是变量定义q是函数定义都是如此Q所以如下的代码会生函数未定义的错误:
var s='function test(){return 1;}';     //一个函数定义语?br /> function demo2(){
    eval(s);
}
demo2();
alert(test());    //->error:test is not defined
        q是因ؓtest函数在局部空间定义,demo2函数内可以访问到Q外面就讉K不到了?/div>

         而在实际的Ajax开发中Q有时我们需要从服务器动态获取代码来执行Q以减轻一ơ蝲入代码过多的问题Q或者是一些代码是通过Javascript自n生成的,希望用eval函数来其执行?br /> 但这L动态获取代码的工作一般在函数内完成,比如Q?/div>
function loadCode(){
    var code=getCode();
    eval(code);
}
       可见eval不可能在全局I间内执行,q就l开发带来了不少问题Q也看到q很多h为此郁闷?/div>
        不过现在偶终于找C解决办法Q嘿嘿,可以同时兼容IE和FirefoxQ方法如下:
var X2={}    //my namespace:)
X2.Eval=function(code){
 if(!!(window.attachEvent && !window.opera)){
  
//ie
  execScript(code); 
 }else{
  
//not ie
  window.eval(code);
 }
}
        现在如果要想在函数内定义全局代码Q就可以通过调用X2.Eval(code)ҎQ一个例子如下:
var s='global';
function demo3(){
 X2.Eval('var s="local"');
}
demo3();
alert(s); //->'local'
        可见Q在demo3函数内重新定义了全局变量s="local"?br />         需要注意的是X2.Evalq不q回|如果要进行表辑ּ的求|q是用系l的eval函数。X2.Eval设计Z做全局代码定义用?/div>
        其实看到q里Q或许有人感觉问题也太容易解决了点,呵呵Q但发现q个办法倒是需要些q气和技巧的Q?br /> Q?Q对于IE览器,默认已经提供了这L函数QexecScriptQ用于在全局I间执行代码Q只是知道的不多?br /> Q?Q对于Firefox览器,直接调用eval函数Q则在调用者的I间执行Q如果调?nbsp;      window.eval则在全局I间执行。这个知道的Z计就更少了。毕竟alert(eval==window.eval)q回trueQ?/div>
         Firefox的eval函数的特点的是很o人奇怪的Q但从javascript规范中倒也能找到其来源Q?/div>
If value of the eval property is used in any way other than a direct call (that is, other than by the explicit use of its
name as an Identifier which is the MemberExpression in a CallExpression), or if the eval property is assigned to,
an EvalError exception may be thrown.
      意思大概就是说eval函数的执行是和调用者相关的Q但q没有说其执行上下文的问题。所以IE和Firefox孰是孰非也就很难说了Q大家知道解军_法就好?/div>
 
 


seal 2009-05-19 10:10 发表评论
]]>
在XHTML中用javascripthttp://www.aygfsteel.com/sealyu/archive/2009/05/13/270406.htmlsealsealWed, 13 May 2009 06:28:00 GMThttp://www.aygfsteel.com/sealyu/archive/2009/05/13/270406.htmlhttp://www.aygfsteel.com/sealyu/comments/270406.htmlhttp://www.aygfsteel.com/sealyu/archive/2009/05/13/270406.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/270406.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/270406.html

Making JavaScript Compatible with XHTML

XHTML is subject to the same syntactical rules as XML. Because of this, an XHTML processor treats the characters < and & as markup, even if they reside inside a <script> block. Since the < and & characters are also used by the JavaScript language, this creates a conflict. When an XHTML processor sees these characters within the JavaScript code of a <script> block, it attempts to parse the JavaScript code as if it were markup, which causes the XHTML parser to fail.

You can get around this conflict and make all JavaScript code compatible with XHTML by placing the JavaScript code within a CDATA section. A CDATA section in XML/XHTML starts with the characters <![CDATA[ and ends with the characters ]]>.

Any characters within the starting and ending element of a CDATA section are not treated by the XML/XHTML processor as markup, thus preventing a conflict.

Here is an example of how to declare JavaScript code within a CDATA section so that it is compatible with XHTML:

<script type="text/javascript">
//<![CDATA[

alert("<This is compatible with XHTML>");

//]]>
</script>

Note that JavaScript source code must be placed within the opening and closing elements of the CDATA section. The CDATA section itself should be commented out with a JavaScript single-line comment // as in the example above. This is so that the JavaScript interrupter does not interpret the CDATA markup as JavaScript, which would cause a JavaScript error.

JavaScript code that is imported into an XHTML document from an external source file is always compatible with XHTML. So, for example, any code you place into the external file external.js and import into an XHTML file via the src attribute of the <script> tag will be valid. Here is an example of how to import the file external.js:

<script type="text/javascript" src="external.js"></script>

在XHTML文档中合适的使用CSS和JavaScript

XHTML™ 1.0 The Extensible HyperText Markup Language (Second Edition) 定义XHTML是ؓ了把HTML 4扩展成像XML 1.0一L应用E序?

在许多站点中XHTML正在q速的替代HTML 4Q然而,L览器对完全支持XHTML斚w表现得不I和网设计师对HTML 4与XHTML的基本差异缺乏理解,产生了当今网l上的一个不断扩大的问题?

XHTML是XML,不是HTML

其中关于XHTML的主要的误解是,它仅仅是另外一个版本的HTML。这个误解生于q样的事实:Microsoft® Internet Explorer只在文g以Mimecd?text/html提交Ӟ才支持XHTMLQ而标准中的类型其实是application/xhtml+xml?

当一个XHTML面的MIMEcd被提交ؓtext/htmlӞ它被所有的览器当作HTML处理Q就好像XHTML比vHTML来没有Q何不同。但是当一个XHTML面的MIMEcd被提交ؓtext/xml?tt>application/xhtml+xmlӞ它将被当作XML文档处理Q而设计和昄XML都是必须要遵守严D则的?

真正的XHTML是一个XML的应用,所以创建XHTML时也要遵守严格的规则。特别是Q?

  1. 未经q处理的<?tt>&不允许出现在CDATA区域Q?tt><!CDATA...>Q之外?
  2. 注释(<!—?... —?gt;)中不能包含双横线?
  3. 包含在注?<!—?... —?gt;)中的内容被忽略?

在内嵌的style?tt>script中出现的问题

在被当作XML而不是HTML处理Ӟ内嵌的style和script标记会生几个不同的问题?

JavaScript中包含了一些在XHTML中不允许存在的字W?

典型的JavaScript中包含了一些特D字W,q些字符在XHTML中是不允许放在CDATA区域之外的?

<script type="text/javascript">

var i = 0;



while (++i < 10)

{

// ...

}

</script>

注意q个例子不是以正格式书写的XHTMLQ因Z用了未经处理?#8220;<”Q它只能在被当作XHTML或XML标记的一部分时出现?

在内嵌的style?tt>script中用注?

熟悉HTML的设计师通常把内嵌的style?tt>script内容攑ֈ注释中,q样可以在不支持样式和脚本的览器中隐藏它们?

<style type="text/css">

<!--

body {background-color: blue; color: yellow;}

-->

</style>

<script type="text/javascript">

<!--

var i = 0;

var sum = 0;



for (i = 0; i < 10; ++i)

{

sum += i;

}

alert('sum = ' + sum);

// -->

</script>

q个例子举例说明了特定的览器可以忽略注释里的内宏V另外,q个例子q显CZ不同的浏览器在处?tt>text/xml或?application/xhtml+xml内容时生的不同问题?

Mozilla 1.1+/Opera 7
不能使用CSSQ也不能执行JavaScript?
Netscape 7.0x/Mozilla 1.0.x
不能使用CSSQ但可以执行JavaScript?
Internet Explorer 5.5+
无法正常昄文档?

包含双横U的内嵌style?tt>script

另一个把JavaScript包含在XHTML文g的注释中产生?a rel="internal" >问题Q与在XHTML的注释中使用双横U会产生的问题一栗?

<script type="text/javascript">

<!--

var i;

var sum = 0;



for (i = 10; i > 0; --i)

{

sum += i;

}

// -->

</script>

使用CDATA替代注释

直接把JavaScript攑օCDATA区域会在低版本不支持XML的浏览器中生问题,不过Q把JavaScript的注?//……)与CDATA一起用,p解决向下兼容的问题了?

<script type="text/javascript">

//<![CDATA[

var i = 0;



while (++i < 10)

{

// ...

}

//]]>

</script>

例子

在注释中使用内嵌style的CSS规则

例子1 - XHTML 1.0 Strict?tt>text/html
q个例子举例说明当CSS规则包含内联和包含在注释中时的XHTML?tt>text/html的行为。这个例子支持Netscape 7.xQMozillaQOpera 7和Internet Explorer 5.5+那一个都能像期望一样应用CSS规则?
例子2 - XHTML 1.0 Strict?tt>text/xml
q个例子举例说明当CSS规则包含内联和包含在注释中时的XHTML?tt>text/xml的行为。这个例子支持Netscape 7.xQMozillaQOpera 7?strong>不支持Internet Explorer 5.5+。注意etscape 7.xQMozilla和Opera同意包含在注释的内联CSS规则被忽略?
例子3 - XHTML 1.0 Strict?tt>application/xhtml+xml
q个例子举例说明当CSS规则包含内联和包含在注释中时的XHTML?tt>application/xhtml+xml的行为。这个例子支持Netscape 7.xQMozillaQOpera 7?strong>不支持Internet Explorer 5.5+。注意etscape 7.xQMozilla和Opera同意包含在注释的内联CSS规则被忽略?

使用外部文g的CSS规则

例子4 - XHTML 1.0 Strict?tt>text/html
q个例子举例说明当在使用外部文g的CSS规则的时候XHTML?tt>text/html的行为。这个例子支持Netscape 7.xQMozillaQOpera 7和Internet Explorer 5.5+?
例子5 - XHTML 1.0 Strict?tt>text/xml
q个例子举例说明当在使用外部文g的CSS规则的时候XHTML?tt>text/xml的行为。这个例子支持Netscape 7.xQMozilla和Opera 7但不支持不支持Internet Explorer 5.5+?
例子6 - XHTML 1.0 Strict?tt>application/xhtml+xml
q个例子举例说明当在使用外部文g的CSS规则的时候XHTML?tt>application/xhtml+xml的行为。这个例子支持Netscape 7.xQMozilla和Opera 7但不支持不支持Internet Explorer 5.5+?

不要在XHTML中内?tt>style?tt>script

用外部文件包含CSS规则和JavaScript来替换内联样式和脚本是创建XHTML最x式,在向后兼Ҏ式时Q如果内容的MIMEcd?tt>text/html?tt>application/xhtml+xml改变时将不会被打断?

q个可能看v来更强烈Q可是,它是未来XHTML要打的问题Q当XHTML?tt>text/html?tt>application/xhtml+xml转移在几q后发生?

如果你仅仅测试你的XHTML?tt>text/html的时候,那么你可能生问题,例如像:不能准确的描q出主题。移动CSS和JavaScript到单独的文g是可靠的ҎQ关于改变你XHTML的服务方式?

理解XHTML 1.0的HTML兼容指导

q个XHTML 1.0 HTML Compatibility Guidelines帮助创徏XHTML文档向后兼容性在那些不能理解XML的老浏览器?

h意那是纯_的XHTML文档Q你不需要用xml-stylesheet处理指导Q但应该使用link涉及的外部文件包含CSS?



另外Q附XHTML的一些规范:
1.所有的标记都必要有一个相应的l束标记
以前?nbsp;HTML ?你可以打开许多标签,? ?nbsp;<p> ?nbsp;<li> 而不一定写对应?nbsp;</p> ?nbsp;</li> 来关闭它?? ?nbsp;XHTML 中这是不合法?XHTML要求有严谨的l构,所有标{ֿd?如果是单独不成对的标{?在标{最后加一?nbsp;"/" 来关闭它.例如:
<br /><img height="80" alt="|页设计? src="http://images/logo_w3cn_200x80.gif"&n ... 00" /> 

2.所有标{元素和属性的名字都必M用小?br /> ?nbsp;HTML ? 一?XHTML 对大写是敏感的,<title> ?nbsp;<TITLE> 是不同的标签.XHTML 要求所有的标签和属性的 名字都必M用小?例如:<BODY> 必须写成 <body> .大小写夹杂也是不被认可的,? ?nbsp;dreamweaver 自动生成的属性名?nbsp;"onMouseOver" 也必MҎ "onmouseover".

3.所有的 XML 标记都必d理嵌?br /> 同样因ؓ XHTML 要求有严谨的l构,因此所有的嵌套都必L序,以前我们q样写的代码:
<p><b></p></b> 
必须修改?
<p><b></b></p> 
是?一层一层的嵌套必须是严格对U?

4.所有的属性必ȝ引号 "" 括v?br /> ?nbsp;HTML ?你可以不需要给属性值加引号,但是?nbsp;XHTML ?它们必须被加引号.例如:
<height=80> 
必须修改?
<height="80"> 
Ҏ情况,你需要在属性值里使用双引?你可以用 ",单引号可以?nbsp;&apos;,例如:
<alt="say&apos;hello&apos;"> 


5.把所?nbsp;< ?nbsp;& ҎW号用编码表C?br /> M于P<Q?不是标签的一部分,都必被~码?nbsp;&lt;
M大于P>Q?不是标签的一部分,都必被~码?nbsp;&gt;
M与号Q?amp;Q?不是实体的一部分?都必被~码?nbsp;&amp;

6.l所有属性赋一个?br /> XHTML 规定所有属性都必须有一个?没有值的重复本w?例如:
<td nowrap> <input type="checkbox" name="shirt" value="medium" checked> 
必须修改?
<td nowrap="nowrap"> <input type="checkbox" name="shirt" value="medium" checked="checked" /> 

7.不要在注释内容中使用 "--","--" 只能发生?nbsp;XHTML 注释的开头和l束,也就是说,在内容中它们不再有效.例如下面的代码是无效?
<!--q里是注?----------q里是注?-> 
用等h者空格替换内部的虚线:
<!--q里是注?===========q里是注?-> 

以上q些规范有的看上L较奇?但这一切都是ؓ了我们的代码有一个统一、唯一的标?便于以后的数据再利用.



seal 2009-05-13 14:28 发表评论
]]>javascript 判断某页面上的表单数据是否改变过 (?http://www.aygfsteel.com/sealyu/archive/2009/05/13/270347.htmlsealsealWed, 13 May 2009 02:02:00 GMThttp://www.aygfsteel.com/sealyu/archive/2009/05/13/270347.htmlhttp://www.aygfsteel.com/sealyu/comments/270347.htmlhttp://www.aygfsteel.com/sealyu/archive/2009/05/13/270347.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/270347.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/270347.html

本文转自Q?/span>http://info.codepub.com/2008/09/info-22582.html

原文如下Q?/span>

使用场合Q当某个面数据修改Ӟ需要执行某些操作时   
在页面的body加蝲事gQonloadQ中加上initFileds()可以记录页面的初始数据
在需要判断页面数据是否改变时调用checkModification()Ҏ可判断数据是否改变
q回gؓtrue是已经改变
q回gؓfalse是没有改变
   
    // 面~辑数据
    var inputsData;
    var textareasData;
    var selectsData;
    // 记录下表单中的原始?br />     function initFileds() {
        var inputs = document.getElementsByTagName("input");
        var textareas = document.getElementsByTagName("textarea");
        var selects = document.getElementsByTagName("select");
        inputsData = new Array(inputs.length);
        for (var i=0;i<inputs.length;i++) {
            inputsData[i] = inputs[i].value;
            if (inputs[i].type=="radio") {
                inputsData[i]=inputs[i].checked;
            }
        }
        textareasData = new Array(textareas.length);
        for (var i=0;i<textareas.length;i++) {
            textareasData[i] = textareas[i].value;
        }
        selectsData = new Array(selects.length);
        for (var i=0;i<selects.length;i++) {
            selectsData[i] = selects[i].value;
        }
    }
    /*
     * 判断表单中值是否被修改?br />      * submitCommand 表单有改动时,执行的javascript代码
     */
    function checkModification(submitCommand) {
        var inputs = document.getElementsByTagName("input");
        var textareas = document.getElementsByTagName("textarea");
        var selects = document.getElementsByTagName("select");
        var hasBeenChanged = false;
        for (var i=0;i<inputs.length;i++) {
            if (inputs[i].type=="radio"&&(inputs[i].checked!=inputsData[i])) {
                hasBeenChanged = true;
                inputsData[i]=inputs[i].checked;
            }
            if (inputs[i].type!="radio"&&inputsData[i]!=inputs[i].value) {
             if(inputs[i].name!="actionType"){
                 hasBeenChanged = true;
                }
                inputsData[i]=inputs[i].value;
            }
        }
        for (var i=0;i<textareas.length;i++) {
            if (textareasData[i]!=textareas[i].value) {
                hasBeenChanged = true;
                textareasData[i]=textareas[i].value;
            }
        }
        for (var i=0;i<selects.length;i++) {
            if (selectsData[i]!=selects[i].value) {
                hasBeenChanged = true;
                selectsData[i]=selects[i].value;
            }
        }
         if (hasBeenChanged&&confirm("数据已经改变,是否保存Q?)) {
             eval(submitCommand);
         }
    }


seal 2009-05-13 10:02 发表评论
]]>
10个基?JavaScript ?WYSIWYG ~辑??http://www.aygfsteel.com/sealyu/archive/2009/04/27/267680.htmlsealsealMon, 27 Apr 2009 02:23:00 GMThttp://www.aygfsteel.com/sealyu/archive/2009/04/27/267680.htmlhttp://www.aygfsteel.com/sealyu/comments/267680.htmlhttp://www.aygfsteel.com/sealyu/archive/2009/04/27/267680.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/267680.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/267680.htmlCOMSHARP CMS 写道Q在U编辑内容的时候,那些Z JavaScript 的编辑器帮了我们大忙Q这些所见即所得(WYSIWYGQ编辑器Q给我们提供了类? Office 的操作体验。如今,M|站内容理pȝQCMSQ和博客pȝ都需要一个这L~辑器。本文精选了10个基?JavaScript  的编辑器Q它们有的是Z jQuery 框架Q有点则不是?/p>

MarkitUp - jQuery

Official Website | Demo
MarkitUp

功能不是很多Q但很轻量,很灵zR打包后只有6.5K大小?/p>

jWYSIWYG - jQuery

Official Website | Demo
jWYSIWYG

非常基本的编辑器Q简单ؓ本。打包后只有7K?/p>

Lightweight RTE- jQuery

Official Website | Demo
jWYSIWYG

单到不能再简单,很容易自׃攏V?/p>

HTMLBox - jQuery

Official Website | Demo
HTMLBox

跨浏览器Q开源,Z jQuery。可以很Ҏ同各U?CMSQ论坛,留言本,博客{系l集成?/p>

D Small Rich Text Editor - jQuery

Official Website | Demo
D Small Rich Text Editor

Z iframe 对象?/p>

WYMEditor - jQuery

Official Website | Demo
WYMEditor

<!-- ################## NON jQUery ################### -->

TinyMCE - non-jQuery

Official Website | Demo
TinyMCE

最l典的基?JavaScript 的编辑器QCOMSHARP CMS 默认的编辑器是q个?/p>

fckeditor - Non-jQuery

Official Website | Demo
fckeditor

功能非常强大?/p>

Yahoo YUI Rich Text Editor - Non-jQuery

Official Website | Demo
Yahoo UI RTE

Z Yahoo YUIQ简单,但很可靠?/p>

Xinha - Non-jQuery

Official Website | Demo
Xinha

自由的基?nbsp; BSD 许可~辑器,功能完善Q很适合同各U系l集成?/p>

本文原文来源Q?a >http://www.queness.com/post/212/10-jquery-and-non-jquery-javascript-rich-text-editors



seal 2009-04-27 10:23 发表评论
]]>
javascript判断变量是否定义http://www.aygfsteel.com/sealyu/archive/2009/03/17/260193.htmlsealsealTue, 17 Mar 2009 02:49:00 GMThttp://www.aygfsteel.com/sealyu/archive/2009/03/17/260193.htmlhttp://www.aygfsteel.com/sealyu/comments/260193.htmlhttp://www.aygfsteel.com/sealyu/archive/2009/03/17/260193.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/260193.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/260193.html 例如Q?br /> if(hasLoaded){
  //Do something here
}
如果此变量还未被定义Q就会报错: 'xxxx' is #790000.

q时Q就需要对q个变量q行判断Q?br /> if(typeof(hasLoaded) != 'undefined'){
  if(hasLoaded){
    //Do something here
  }
}




seal 2009-03-17 10:49 发表评论
]]>
?Javascript 获取指定面元素的位|?/title><link>http://www.aygfsteel.com/sealyu/archive/2009/02/23/256188.html</link><dc:creator>seal</dc:creator><author>seal</author><pubDate>Mon, 23 Feb 2009 03:34:00 GMT</pubDate><guid>http://www.aygfsteel.com/sealyu/archive/2009/02/23/256188.html</guid><wfw:comment>http://www.aygfsteel.com/sealyu/comments/256188.html</wfw:comment><comments>http://www.aygfsteel.com/sealyu/archive/2009/02/23/256188.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sealyu/comments/commentRss/256188.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sealyu/services/trackbacks/256188.html</trackback:ping><description><![CDATA[?nbsp;Javascript 获取指定面元素的位|是一个非常常见的需求,本文介绍的方法能够准返回一个元素相对于整个文档左上角的坐标Q即元素?nbsp;top 、left 的位|,而且能够兼容览器,怿Ҏ手非常有用?br /> <br /> <div> <div> <div><a onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy to clipboard</a><a onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a></div> </div> <ol start="1"> <li><script language="javascript" type="text/javascript">  </li> <li>  </li> <li><!--    </li> <li>  </li> <li>// 说明Q用 Javascript 获取指定面元素的位|?nbsp;  </li> <li>  </li> <li>// 整理Qhttp://www.codebit.cn   </li> <li>  </li> <li>// 来源QYUI DOM    </li> <li>  </li> <li>function getElementPos(elementId) {  </li> <li>  </li> <li>    var ua = navigator.userAgent.toLowerCase();       </li> <li>  </li> <li>    var isOpera = (ua.indexOf('opera') != -1);       </li> <li>  </li> <li>    var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof        </li> <li>  </li> <li>    var el = document.getElementById(elementId);   </li> <li>  </li> <li>          </li> <li>  </li> <li>    if(el.parentNode === null || el.style.display == 'none'){ return false; }        </li> <li>  </li> <li>    var parent = null;  </li> <li>  </li> <li>    var pos = [];     //不定长数l?  </li> <li>  </li> <li>    var box;        </li> <li>  </li> <li>    if(el.getBoundingClientRect){  //IE       </li> <li>  </li> <li>        box = el.getBoundingClientRect();          </li> <li>  </li> <li>        var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);          </li> <li>  </li> <li>        var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);            </li> <li>  </li> <li>        return {x:box.left + scrollLeft, y:box.top + scrollTop};       </li> <li>  </li> <li>    }else if(document.getBoxObjectFor){   // gecko                  </li> <li>  </li> <li>        box = document.getBoxObjectFor(el);                       </li> <li>  </li> <li>        var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;           </li> <li>  </li> <li>        var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;            </li> <li>  </li> <li>        pos = [box.x - borderLeft, box.y - borderTop];       </li> <li>  </li> <li>    }else{    // safari & opera       </li> <li>  </li> <li>        pos = [el.offsetLeft, el.offsetTop];          </li> <li>  </li> <li>        parent = el.offsetParent;           </li> <li>  </li> <li>        if (parent != el) {  </li> <li>  </li> <li>            while (parent) {                   </li> <li>  </li> <li>                pos[0] += parent.offsetLeft;                 </li> <li>  </li> <li>                pos[1] += parent.offsetTop;               </li> <li>  </li> <li>                parent = parent.offsetParent;              </li> <li>  </li> <li>            }  </li> <li>  </li> <li>        }           </li> <li>  </li> <li>        if (ua.indexOf('opera') != -1  || ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' )){                </li> <li>  </li> <li>            pos[0] -= document.body.offsetLeft;               </li> <li>  </li> <li>            pos[1] -= document.body.offsetTop;           </li> <li>  </li> <li>        }        </li> <li>  </li> <li>    }              </li> <li>  </li> <li>    if (el.parentNode) {   </li> <li>  </li> <li>        parent = el.parentNode;   </li> <li>  </li> <li>    } else {   </li> <li>  </li> <li>        parent = null;   </li> <li>  </li> <li>    }         </li> <li>  </li> <li>    while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') { // account for any scrolled ancestors          </li> <li>  </li> <li>        pos[0] -= parent.scrollLeft;           </li> <li>  </li> <li>        pos[1] -= parent.scrollTop;        </li> <li>  </li> <li>        if (parent.parentNode) {   </li> <li>  </li> <li>            parent = parent.parentNode;   </li> <li>  </li> <li>        } else {   </li> <li>  </li> <li>            parent = null;   </li> <li>  </li> <li>        }       </li> <li>  </li> <li>    }       </li> <li>  </li> <li>    return {x:pos[0], y:pos[1]};  </li> <li>  </li> <li>}  //-->   </li> <li>  </li> <li></script>  <br /> </li> </ol> </div> <br /> <br /> W二U方法:<br /> function WebForm_GetElementPosition(element) {<br />     var result = new Object();<br />     result.x = 0;<br />     result.y = 0;<br />     result.width = 0;<br />     result.height = 0;<br />     if (element.offsetParent) {<br />         result.x = element.offsetLeft;<br />         result.y = element.offsetTop;<br />         var parent = element.offsetParent;<br />         while (parent) {<br />             result.x += parent.offsetLeft;<br />             result.y += parent.offsetTop;<br />             var parentTagName = parent.tagName.toLowerCase();<br />             if (parentTagName != "table" &&<br />                 parentTagName != "body" && <br />                 parentTagName != "html" && <br />                 parentTagName != "div" && <br />                 parent.clientTop && <br />                 parent.clientLeft) {<br />                 result.x += parent.clientLeft;<br />                 result.y += parent.clientTop;<br />             }<br />             parent = parent.offsetParent;<br />         }<br />     }<br />     else if (element.left && element.top) {<br />         result.x = element.left;<br />         result.y = element.top;<br />     }<br />     else {<br />         if (element.x) {<br />             result.x = element.x;<br />         }<br />         if (element.y) {<br />             result.y = element.y;<br />         }<br />     }<br />     if (element.offsetWidth && element.offsetHeight) {<br />         result.width = element.offsetWidth;<br />         result.height = element.offsetHeight;<br />     }<br />     else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {<br />         result.width = element.style.pixelWidth;<br />         result.height = element.style.pixelHeight;<br />     }<br />     return result;<br /> } <br /> <img src ="http://www.aygfsteel.com/sealyu/aggbug/256188.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sealyu/" target="_blank">seal</a> 2009-02-23 11:34 <a href="http://www.aygfsteel.com/sealyu/archive/2009/02/23/256188.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IE屏蔽window.open()H口的解军_?/title><link>http://www.aygfsteel.com/sealyu/archive/2008/11/08/239429.html</link><dc:creator>seal</dc:creator><author>seal</author><pubDate>Sat, 08 Nov 2008 09:16:00 GMT</pubDate><guid>http://www.aygfsteel.com/sealyu/archive/2008/11/08/239429.html</guid><wfw:comment>http://www.aygfsteel.com/sealyu/comments/239429.html</wfw:comment><comments>http://www.aygfsteel.com/sealyu/archive/2008/11/08/239429.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sealyu/comments/commentRss/239429.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sealyu/services/trackbacks/239429.html</trackback:ping><description><![CDATA[作者: sealyu   日期Q?008-11-8<br /> <br /> 今天在开发的时候,到客户提到的一个问题,<br /> 每次在下载文件的时候,IE都会L打开的保存文件的对话框?br /> 看了一下代码,发现目使用了一个stream servlet来处理文件下载,在用ajaxq回面后,使用window.open(link);打开保存对话框?br /> 问题应该处在这里了QGoogle了一下,发现q是׃IE的安全机制?br /> 在微软的|站上有q么一D话Q?br /> <h1 class="title">Pop-Up Blocking</h1> <div id="wmqeeuq" class="intro"> <p>The Pop-up Blocking feature blocks pop-up (and pop-under) windows initiated automatically by a Web site. Internet Explorer blocks Pop-up windows in the <a target="_blank" logredir="CTT=ToExternal">Internet and Restricted sites zones</a> <script language="Javascript"> if(typeof(IsPrinterFriendly) != "undefined") { var l = "http://go.microsoft.com/fwlink/?linkid=26003"; var nl; var c = l.charAt(0); var o = document.getElementById("EKE"); switch (c){ case "/": nl=(" [http://" + document.domain + l + "]"); break case "#": nl=(""); break default: nl=" [" + l + "]" } if(o != null) o.innerHTML = nl; } </script> by default. However, the Pop-up Blocker enables pop-up windows initiated by a user action. Users can configure Internet Explorer 6 for Windows XP with SP2 to be more or less restrictive. Users can also turn off the Pop-up Blocker altogether. Generally, the Pop-up Blocker enables a window to open under the following circumstances:</p> <table border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listBullet" valign="top">•</td> <td class="listItem"> <p>When initiated by user action, such as clicking a button or hyperlink</p> </td> </tr> <tr> <td class="listBullet" valign="top">•</td> <td class="listItem"> <p>When opened in the <a target="_blank" logredir="CTT=ToExternal">Trusted sites and Local intranet zones</a> <script language="Javascript"> if(typeof(IsPrinterFriendly) != "undefined") { var l = "http://go.microsoft.com/fwlink/?linkid=26003"; var nl; var c = l.charAt(0); var o = document.getElementById("EWE"); switch (c){ case "/": nl=(" [http://" + document.domain + l + "]"); break case "#": nl=(""); break default: nl=" [" + l + "]" } if(o != null) o.innerHTML = nl; } </script> (considered safe)</p> </td> </tr> <tr> <td class="listBullet" valign="top">•</td> <td class="listItem"> <p>When opened by other applications running on the local computer</p> </td> </tr> </tbody> </table> <p>The affected script methods are:</p> <pre class="codeSample">window.open<br /> window.showHelp<br /> window.showModalDialog<br /> window.showModelessDialog<br /> window.external<br /> window.NavigateAndFind</pre> <table class="sidebarContent" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr style="padding: 0px 0px 7px;" onclick=""> <td class="dropCapQ" style="vertical-align: top;" align="left" nowrap="nowrap"><br /> </td> <td style="vertical-align: top;"> <h5><img src="http://technet2.microsoft.com/library/gallery/templates/MNP2.Common/images/note.gif" alt="" border="0" height="10" width="10" />注:</h5> </td> </tr> <tr class="" id="eCE6E" style="padding: 0px 0px 7px;" valign="top"> <td class="dropCapQ" align="right" nowrap="nowrap"><br /> </td> <td> <p>Pop-ups created with <font face="Courier New"><strong>window.createPopup</strong></font> are unaffected by the Pop-up Blocker.</p> </td> </tr> </tbody> </table> </div> <p style="text-indent: 2em;">在web~程q程中,l常会遇C些页面需要弹出窗口,但是在服务器端用window.open弹出的窗口会被IEL掉,<a><font color="#43699a">showModalDialog</font></a>弹出的窗口有时ƈ不能满我们需要,我们需要弹出新的浏览器H口?/p> <p style="text-indent: 2em;"> Z么我们编写的弹出H口会被IEL呢,原来IE会自动判断弹出窗口的状态,它会L自动弹出的窗口,而通过我们用鼠标点d出的H口Q它是不会阻止的。这里就有一个问题,有h_我的E序是写在服务器按钮里的Q也是通过鼠标点击弹出的呀Q其实只有在加蝲面后,我们点击到弹D|间页面没有被重新加蝲的情况下Q弹出的H口才不会被LQ这也就是说Q写在服务器控g的回传事仉的window.open都会被阻止?br /> <br /> l箋Google解决办法Q在分析了几U解x法ƈq行Ҏ之后Q发现最单有效的Ҏ如下Q?br /> 在window.open()函数中增加一个参敎ͼtarget讄?#8216;self’Q?br /> xZ用: window.open(link,'_self');<br /> 问题解决?/p> <br /> <img src ="http://www.aygfsteel.com/sealyu/aggbug/239429.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sealyu/" target="_blank">seal</a> 2008-11-08 17:16 <a href="http://www.aygfsteel.com/sealyu/archive/2008/11/08/239429.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对FckEditor~辑器在MAXTHON览器下选择服务器文件对话框昄不正常的改进 -...Q{载)http://www.aygfsteel.com/sealyu/archive/2008/04/10/192009.htmlsealsealThu, 10 Apr 2008 14:53:00 GMThttp://www.aygfsteel.com/sealyu/archive/2008/04/10/192009.htmlhttp://www.aygfsteel.com/sealyu/comments/192009.htmlhttp://www.aygfsteel.com/sealyu/archive/2008/04/10/192009.html#Feedback0http://www.aygfsteel.com/sealyu/comments/commentRss/192009.htmlhttp://www.aygfsteel.com/sealyu/services/trackbacks/192009.html 思\是ZIE内核的浏览器采用模态对话框弹出览服务器窗口,其他的仍然window.open不变 1:修改"fckeditor"editor"dialog"common"fck_dialog_common.js
 1 function OpenFileBrowser( url, width, height )
 2 {
 3     // oEditor must be defined.
 4 
 5     var iLeft = ( oEditor.FCKConfig.ScreenWidth  - width ) / 2 ;
 6     var iTop  = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;
 7 
 8     var sOptions = "toolbar=no,status=no,resizable=no,dependent=yes,scrollbars=yes" ;
 9     sOptions += ",width=" + width ;
10     sOptions += ",height=" + height ;
11     sOptions += ",left=" + iLeft ;
12     sOptions += ",top=" + iTop ;
13 
14     // The "PreserveSessionOnFileBrowser" because the above code could be
15     // blocked by popup blockers.
16     if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE )
17     {
18         // The following change has been made otherwise IE will open the file
19         // browser on a different server session (on some cases):
20         // http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
21         // by Simone Chiaretta.
22         var oWindow = oEditor.window.open( url, 'FCKBrowseWindow', sOptions ) ;
23 
24         if ( oWindow )
25         {
26             // Detect Yahoo popup blocker.
27             try
28             {
29                 var sTest = oWindow.name ; // Yahoo returns "something", but we can't access it, so detect that and avoid strange errors for the user.
30                 oWindow.opener = window ;
31             }
32             catch(e)
33             {
34                 alert( oEditor.FCKLang.BrowseServerBlocked ) ;
35             }
36         }
37         else
38             alert( oEditor.FCKLang.BrowseServerBlocked ) ;
39     }
40     else
41     {    
            //q里是修攚w?br />
42         if(oEditor.FCKBrowserInfo.IsIE)
43         {
44             window.showModalDialog(url+"&rdm="+new Date(),window,"status:false;dialogWidth:"+width+"px;dialogHeight:"+height+"px""");
45         }
46         else
47         {
48             window.open( url, 'FCKBrowseWindow', sOptions ) ;
49         }
50     }
51 }

2:修改"fckeditor"editor"filemanager"browser"default"frmresourceslist.html
function OpenFile( fileUrl )
{
    
if( window.dialogArguments)
    {
        window.dialogArguments.SetUrl( fileUrl ) ;
        window.close() ;
        window.dialogArguments.focus() ;
    }
    
else
    {    
        window.top.opener.SetUrl( fileUrl ) ;
        window.top.close() ;
        window.top.opener.focus() ;    
    }
}


seal 2008-04-10 22:53 发表评论
]]>
FireFox ?window.close()有时不能关闭 问题的解?/title><link>http://www.aygfsteel.com/sealyu/archive/2008/04/10/192007.html</link><dc:creator>seal</dc:creator><author>seal</author><pubDate>Thu, 10 Apr 2008 14:51:00 GMT</pubDate><guid>http://www.aygfsteel.com/sealyu/archive/2008/04/10/192007.html</guid><wfw:comment>http://www.aygfsteel.com/sealyu/comments/192007.html</wfw:comment><comments>http://www.aygfsteel.com/sealyu/archive/2008/04/10/192007.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.aygfsteel.com/sealyu/comments/commentRss/192007.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/sealyu/services/trackbacks/192007.html</trackback:ping><description><![CDATA[<div>最q做目的时候碰C个问题:</div> <div>在js里面使用window.close()QIE下工作正常,但是FireFox下有时可以,有时不行?/div> <div>搜烦发现Q可以这栯冻I</div> <div><script   language="javascript"   type="text/javascript">   <br />     <br />   function   closeWindow()   {   <br />     <br />   window.open('','_parent','');   <br />     <br />   window.close();   <br />     <br />   }   <br />     <br />   </script>     <br />   <a   href="javascript:closeWindow();">Close   Window</a></div> <div> </div> <div>在前面加一?nbsp; window.open('','_parent','');   </div> <div>作用为:</div> <div>fool   the   browser   into   thinking   that   it   was   opened   with   a   script   <br />   This   opens   a   new   page,   (non-existent),   into   a   target   frame/window,   (_parent   which   of   course   is   the   window   in   which   the   script   is   executed,   so   replacing   itself),   and   defines   parameters   such   as   window   size   etc,   (in   this   case   none   are   defined   as   none   are   needed).   Now   that   the   browser   thinks   a   script   opened   a   page   we   can   quickly   close   it   in   the   standard   way…</div> <img src ="http://www.aygfsteel.com/sealyu/aggbug/192007.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/sealyu/" target="_blank">seal</a> 2008-04-10 22:51 <a href="http://www.aygfsteel.com/sealyu/archive/2008/04/10/192007.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ګ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʯȪ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">û</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">γ</a>| <a href="http://" target="_blank">ͼ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ž</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Т</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ֹ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">º</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ѱ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ζ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Զ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʷ</a>| <a href="http://" target="_blank">ͨ</a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>