Javascript无法做的事情

While there are a great many things that JavaScript can be used to enhance your web pages and improve your visitors' experience with your site, there are also a few things that JavaScript can't do. Some of these limitations are due to the fact that the script is running in the browser window and therefore cannot access the server while others are as a result of security that is in place to stop web pages from being able to tamper with your computer. There is no way to work around these limitations and anyone who claims to be able to perform any of the following tasks using JavaScript has not considered all of the aspects of whatever it is that they are trying to do.

尽管有很多可以使用JavaScript来增强您的网页并改善访问者对您的网站的体验的东西,但是还有一些JavaScript无法做到的事情。 这些限制中的某些限制是由于该脚本正在浏览器窗口中运行,因此无法访问服务器,而其他限制则是由于适当的安全性而阻止网页能够篡改您的计算机。 无法克服这些限制,任何声称能够使用JavaScript执行以下任何任务的人都没有考虑他们正在尝试做的所有事情。

没有服务器端脚本的帮助,它无法写入服务器上的文件 ( It Cannot Write to Files on the Server Without the Help of a Server-Side Script )

Using Ajax, JavaScript can send a request to the server. This request can read a file in XML or plain text format but it cannot write to a file unless the file called on the server actually runs as a script to do the file write for you.

使用Ajax,JavaScript可以将请求发送到服务器。 该请求可以读取XML或纯文本格式的文件,但是它不能写入文件,除非在服务器上调用的文件实际上是作为脚本运行的,以便为您执行文件写入。

JavaScript cannot access databases unless you use Ajax and have a server-side script to perform the database accesses for you.

除非您使用Ajax并具有服务器端脚本来为您执行数据库访问,否则JavaScript无法访问数据库

它无法读取或写入客户端中的文件 ( It Cannot Read From or Write to Files in the Client  )

Even though JavaScript is running on the client computer (the one where the web page is being viewed) it is not allowed to access anything outside of the web page itself. This is done for reasons of security since otherwise a web page would be able to update your computer to install who knows what. The only exception to this are files called cookies which are small text files that JavaScript can write to and read from. The browser restricts access to cookies so that a given web page can only access cookies created by the same site.

即使JavaScript在客户端计算机(正在查看网页的客户端计算机)上运行,也不允许访问该网页本身以外的任何内容。 这样做是出于安全原因,因为否则网页将能够更新您的计算机以安装知道谁的人。 唯一的例外是称为Cookie的文件,它们是JavaScript可以读写的小文本文件。 浏览器限制对cookie的访问,因此给定的网页只能访问由同一站点创建的cookie。

JavaScript cannot close a window if it didn't open it. Again this is for security reasons.

JavaScript无法打开的窗口无法关闭 。 再次出于安全原因。

它无法访问托管在另一个域上的网页 ( It Cannot Access Web Pages Hosted on Another Domain )

Even though web pages from different domains can be displayed at the same time, either in separate browser windows or in separate frames within the same browser window, the JavaScript running on a web page belonging to one domain cannot access any information about a web page from a different domain. This helps to ensure that private information about you that may be known to the owners of one domain is not shared with other domains whose web pages you may have open concurrently. The only way to access files from another domain is to do an Ajax call to your server and have a server side script access the other domain.

即使可以同时显示来自不同域的网页,无论是在单独的浏览器窗口中还是在同一浏览器窗口中的单独框架中,在属于一个域的网页上运行JavaScript都无法从以下位置访问有关该网页的任何信息一个不同的域。 这有助于确保一个域的所有者可能知道的有关您的私人信息不会与您可能同时打开其网页的其他域共享。 访问来自另一个域的文件的唯一方法是对服务器进行Ajax调用,并让服务器端脚本访问另一个域。

它不能保护您的页面源或图像 ( It Cannot Protect Your Page Source or Images )

Any images on your web page are downloaded separately to the computer displaying the web page so the person viewing the page already has a copy of all of the images by the time they view the page. The same is true of the actual HTML source of the web page. The web page needs to be able to decrypt any web page that is encrypted in order to be able to display it. While an encrypted web page may require JavaScript to be enabled in order for the page to be able to be decrypted in order for it to be able to be displayed by the web browser, once the page has been decrypted anyone who knows how can easily save the decrypted copy of the page source.

网页上的所有图像都单独下载到显示该网页的计算机上,因此查看该页面的人在查看该页面时已经拥有所有图像的副本。 网页的实际HTML源也是如此。 网页需要能够解密任何已加密的网页,以便能够显示它。 尽管加密的网页可能需要启用JavaScript才能解密该网页,以便该网页能够被网络浏览器显示,但是解密该网页后,任何知道如何进行保存的人都可以轻松保存页面源的解密副本。

翻译自: https://www.thoughtco.com/what-javascript-cannot-do-2037666

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值