您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 网页制作完全手册
  所属分类: Web开发
  开发工具:
  文件大小: 3mb
  下载次数: 0
  上传时间: 2013-09-05
  提 供 者: u0117*****
 详细说明: Tips and Tricks Internet Development Index -------------------------------------------------------------------------------- As with any type of programming, writing bug-free, efficient scripts that meet your expectations takes a bit of work. The following sections provide some tips and hints to make that work take less time and go more smoothly. Checking the Internet Explorer Version Number Canceling a Button Click Preventing a Document From Being Cached Using Objects Replacing Custom Controls with DHTML Checking the Intern et Explorer Version Number You should always check for the type and version of the client browser, so that your content degrades gracefully if the client browser does not support features on your Web site. The easiest way to identify a browser and its characteristics (browser code name, version number, language, etc.) in script is through the Dynamic HTML (DHTML)?A HREF="objects/obj_navigator.html">navigator object. You can also access this object and its properties in C++ applications through the IOmNavigator interface. The userAgent property of the navigator object returns a string that includes the browser and browser version. The following example Microsoft® JScript® function runs on most browsers and returns the version number for any Microsoft Internet Explorer browser and zero for all other browsers. SHOWExample function msieversion() // Return Microsoft Internet Explorer (major) version number, or 0 for others. // This function works by finding the "MSIE " string and extracting the version number // following the space, up to the semicolon { var ua = window.navigator.userAgent var msie = ua.indexOf ( "MSIE " ) if ( msie > 0 ) // is Microsoft Internet Explorer; return version number return parseFloat ( ua.substring ( msie+5, ua.indexOf ( ";", msie ) ) ) else return 0 // is other browser } When checking browser version numbers, always check for version numbers greater than or equal to a target version. In this way, your Web site will be be compatible with future versions of the browser. For example, if you have designed your content for the latest version of Internet Explorer, use that version number as a minimum version number. Note Browsers often have several releases of a browser version. For example, 4.01, 5.0, 5.5 and 6.0b are all different versions of Internet Explorer. The 'b' in 6.0b represents a beta version of Internet Explorer 6. As of Internet Explorer 5, conditional comments are available as an alternative technique for detecting browser versions. Conditional comments have the advantage of not using a script block, which means that it is not always necessary to use scripting and DHTML when working with conditional comments. When no scripting is used in a Web page, no scripting engine needs to be loaded. Conditional comments are processed during the downloading and parsing phase, so only the content that is targeted for the browser loading the Web page is actually downloaded. Conditional comments can be combined freely with other browser detection techniques. For more information, see About Conditional Comments. Canceling a Button Click The following HTML example shows a common scripting mistake related to event handling and canceling the default action. SHOWExample Canceling the Default Action
1 Without return (won't work)
2 With return (works)
3 Function pointer (works) The first a element in this example does not work properly. Without the return in the onclick燡Script expression, the browser interprets the function expression, throws away the resulting value, and leaves the default action unaffected. The other a elements correctly bind the return value to the event, hence the default action can be canceled when false is returned. Preventing a Document From Being Cached You can prevent a document from being cached by adding the following meta tag to the document. Preventing the document from being cached ensures that a fresh copy of the document will always be retrieved from the site, even during the user's current session, regardless of how the user has set the browser's caching options. This is useful if the content of the document changes frequently. Using Objects Objects are Microsoft® ActiveX® Controls or other similar components that provide custom capabilities and services for HTML documents. You can add a control to your document using the object element, and you can gain access to the capabilities and services of the control using its properties and methods from script. When using objects, be aware that DHTML extends every object by providing these additional properties: align classid code codeBase codeType data form height name object recordset type width If a control has properties with these same names, you will not be able to access the properties unless you preface the name with the object property. For example, assume that an ActiveX control is added to the document using the following: In this example, there are two widths: an extended property set within the object element, and a property belonging to the control that is set using the param element. To access these from script, you use the following code. alert(MyControl.width); // this is Dynamic HTML's property; displays "200" alert(MyControl.object.width); // this is the object's property; displays "400" Replacing Custom Controls with DHTML DHTML provides everything you need to generate animated effects without resorting to custom controls. For example, consider the following script, which is a replacement for the Path control. SHOWExample var tickDuration; tickDuration = 50; var activeObjectCount; var activeObjects; var itemDeactivated; var tickGeneration; activeObjects = new Array(); activeObjectCount = 0; timerRefcount = 0; itemDeactivated = false; tickGeneration = 0; function initializePath(e) { e.waypointX = new Array(); e.waypointY = new Array(); e.duration = new Array(); } function addWaypoint(e, number, x, y, duration) { e.waypointX[number] = x; e.waypointY[number] = y; e.duration[number] = duration; } function compact() { var i, n, c; n = new Array(); c = 0; itemDeactivated = false; for (i=0; i e.ticks) { e.active = false; itemDeactivated = true; if (e.onpathcomplete != null) { window.pathElement = e; e.onpathcomplete() } } } To use this script in your document, do the following: Load the script using the src attribute of the script element. Initialize the paths using the initializePath function. Set the way points using the addWaypoint function. Set the path-complete handlers using the runWaypoint function. The following sample document shows how this works. SHOWExample
Item1
Item2
Item3
Item4
Item5
Item6
Generation
Show Me ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 网页
 输入关键字,在本站1000多万海量源码库中尽情搜索: