1. Home
  2. Computing & Technology
  3. JavaScript

Javascript and the Browser
Limitations on what you can do with Javascript

By , About.com Guide

Many of the Javascript questions asked by beginners in various forums are some variant of the question "How do I change the visitor's browser to the size, configuration, setup that I want it to have?" They want to block the context menu or resize the browser window or open a new window in a set position or some other thing that changes the browser from working the way that the browser owner has set it to work to the way that the web page author of the currently displayed page wants it to work.

There are a number of answers that apply to many of these types of questions so if you have a question about how to use Javascript to make changes to your visitors browser then the following information will help you to answer it.

  1. There are three parts to Javascript - the core part that does the processing, the DOM (document object model) part that interfaces with the web page, and the BOM (browser object model) part that interfaces with the browser itself. There are no standards for this last part and so the way that you need to write the code to interact with one specific browser may be different from that which a different browser uses.
  2. Newer browsers tend to provide less options for Javascript to interact with the browser than earlier browsers did. Those options which newer browsers have discontinued are ones which have been used by some people to compromise the security of the browser. If you are wondering why certain browsers don't allow you to turn off certain bars when you open a new window or why you can't update the status bar with your content it is because others have abused those options in the past. The browser has disabled that option in order to prevent such abuse.
  3. Newer browsers provide configuration options allowing the browser owner to decide whether web pages should be able to position or resize new windows and whether it should be opened as a new window or tab. You should consider the options that you specify as the third parameter of the window.open statement to be suggestions only and not expect all browsers to open a new window the way you have specified.
  4. If you attach your own contextmenu this will not override the standard contextmenu in most browsers. Many will display the standard menu in front of yours making yours inaccessible. Some browsers also completely disregard any attempt to disable the context menu. Since many of your visitors will be actually using thhe standard context menu to navigate between web sites where their browser does allow you to change or disable the contextmenu you are actually preventing them from being able to use their browser properly and their first response will probably be to leave your site never to return.
  5. Javascript has no file access on your visitor's computer whatsoever apart from cookies. A given domain can set up to 20 cookies and a browser will store up to 300 cookies in all. Once the 20 or 300 limit is reached the oldest cookie will be discarded and replaced with the new one being written. The standards state that each cookie can be up to 4096 characters but some browser apply this as a per site limit instead of as a per cookie limit. JScript can use ActiveX to read and write files on your visitor's computer but this only works in Internet Explorer, is intended for use on intranets and not on the internet, and has to be specifically enabled in the browser inn order to work.
  6. The only way that you can guarantee that a new window will actually open and not be blocked by a popup blocker is if the window is being opened in response to your visitor clicking on a link. Even then you can't be sure of the size or position of the window as the browser may have disabled your ability to set that. If you want control of what you are displaying then you should display the new information as an in-page popup rather than opening a new window.
  7. The resolution that your visitor's screen is set to is irrelevant unless you are asking the browser to open a new window in the centre of the screen and hoping that the browser will comply with your request. Most desktops have at least one fixed toolbar that takes up a certain space on the screen. The browser too will take up a certain amount of space to display the various toolbars etc (this is known as the browser chrome). As each visitor may have different settings for their operating system and browser and may also choose to have their browser only take up part of the screen there is no way to tell how much space is available in the browser window fron the screen resolution. If you want to know the space in the browser then you should test for this directly. Internet Explorer uses two different methods of providing this information depending on the DOCTYPE and other browsers use a different method again.
  8. Any information that the browser provides to the page as to what operating system it is depends on which browser version you are running. Browsers cannot correctly report on operating systems that have been released since the browser was. The other fields within the navigator object are also not all that useful as most of the fields are able to be changed by changing the browser configuration and most browsers can be configured to identify themselves as Internet Explorer.

Overall, Javascript works very well at communicating with the actual web page that it is attached to but has very little access to anything outside the web page. What access that it does have to information about the browser is less in modern browsers than it was in earlier ones and tends to be access to get information rather than to be able to change anything outside of the page. Whatever processing that you do manage to get to work that doesn't involve the current web page will almost certainly be disabled in future browsers. Also where you do something with Javascript that involves changes to the browser or anything else that interferes with your visitors carefully selected browser settings you run the risk of alienating them and having them leave your site.

Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript
  4. Problem Solving
  5. Javascript and the Browser>

©2009 About.com, a part of The New York Times Company.

All rights reserved.