ホームページ  >  記事  >  ウェブフロントエンド  >  JavaScript基本Q&A2_基礎知識

JavaScript基本Q&A2_基礎知識

WBOY
WBOYオリジナル
2016-05-16 18:57:49956ブラウズ

4. JavaScript的局限性(JavaScript Lminitations

Q:JavaScript程序不能做什么?

A:JavaScript代码不能做下列事情:

  • 不能使用用户系统上或者客户端局域网中的打印机或者其他设备。

    (解决方法,见打印JavaScript输出。)

  • 不能直接访问用户系统或者客户端局域网中的文件;唯一例外就是可以访问浏览器的Cookie文件。

    (解决方法,见文件访问部分。)

  • 不能直接访问Web服务器上的文件。

    (解决方法,见文件访问部分。)

  • 实现多重处理或多线程。

如果你的确需要访问文件或者执行其他“特权”操作,可以JavaScript和Java applet结合使用。已签名的Java applet允许进行特权操作,同时,JavaScript可以和applet交换信息。然而,你必须明白JavaScript/Java最大的限制是:用户可能一直禁止使用JavaScript或者Java或者二者。

 

5. 支持JavaScript的浏览器(Browsers Supporting JavaScript

Q:那些浏览器支持JavaScript?

A:下列浏览器都支持JavaScript:

  • Netscape Navigator (从2.0开始)
  • Microsoft Internet Explorer (从3.0开始)
  • 其他厂商许可或者实现了JavaScript解释器的浏览器或者产品(如Opera)。

参见JavaScript的版本

 

6. JavaScript的版本(JavaScript Versions

Q:JavaScript有哪些版本?

A:JavaScript是新兴的编程语言之一。它第一次实现是有Netscape社区在1995完成。第一个支持JavaScript的浏览器是Netscape Navigator 2.0 beta 版。截止1999年,两大主流浏览器,Netscape Navigator和Microsoft Internet Explorer对客户端JavaScript主要支持以下版本:

浏览器

年份

JavaScript版本

Netscape Navigator 2.0 1995 JavaScript 1.0
Microsoft Internet Explorer 3.0 1996 JavaScript 1.0 (JScript 1.0)
Netscape Navigator 3.0 1996 JavaScript 1.1
Netscape Navigator 4.0 1997 JavaScript 1.2
Microsoft Internet Explorer 4.0 1997 JavaScript 1.2 (JScript 3.0)
Netscape Navigator 4.5 1998 JavaScript 1.3
Microsoft Internet Explorer 5.0 1999 JavaScript 1.3 (JScript 5.0)

Unfortunately, Netscape and Microsoft's JavaScript implementations are different, even with the same version number of JavaScript. For example, JavaScript 1.0 in IE3 is different from JavaScript 1.0 in Netscape Navigator 2; similarly, JavaScript 1.2 in IE4 is different from JavaScript 1.2 in Netscape Navigator 4.

In addition to these versions, third parties can also create their own JavaScript implementations, or license Microsoft or Netscape's JavaScript technology. For example, the Opera browser supports JavaScript.

What does cross-platform coding mean? Essentially, you have to use one of the following techniques:

  • Use only a subset of the JavaScript language supported by all browsers and/or
  • Write different codes for different browsers and detect the actual browser at runtime

7. JavaScript documentation (JavaScript Documentation)

Q: Where can I get documentation for JavaScript?

A: Online JavaScript documentation can be found at these sites:

In addition, you can also find JavaScript discussions, online guides, links, code samples, and hundreds of useful scripts from the following websites (of course this list is not exhaustive and is only used as a starting point):

8. Printing JavaScript Output (Printing JavaScript Output)

Q: How do I print JavaScript output?

A: JavaScript programs cannot directly access the printer. However, by going to File | Print in the browser menu (or using the shortcut, Ctrl P on Windows), users can print anything on the web page, including the output of JavaScript programs.

If users need to print your script output frequently, then you can:

  • Prompt them to use the File|Print menu and/or
  • Use the window.print() method to open the print window.

Alternatively, your script can generate print content in a separate browser window (see example below).

Example: This script generates a multiplication table, outputs it to a new browser window, and explains to the user how to print it.

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。