Web Development with JavaScript and Ajax Illuminated by Xiang Fu & Lixin Tao & Kai Qian & Richard Allen

Web Development with JavaScript and Ajax Illuminated by Xiang Fu & Lixin Tao & Kai Qian & Richard Allen

Author:Xiang Fu & Lixin Tao & Kai Qian & Richard Allen [Xiang Fu]
Language: eng
Format: epub
Tags: JavaScript, Web Development
Publisher: Jones & Bartlett Learning
Published: 2010-10-21T21:00:00+00:00


5.3 Hidden IFrame

Long before there was widespread browser support for, or use of, an XML-HttpRequest object, developers were using hidden frames to make requests to the server without reloading the page that the user is viewing. The <frame> and <iframe> tags became an official part of the HTML specification with version 4.0 in April 1998. A frame is essentially a window that is embedded in the browser's main window. Frames are independent of the main window in that they can load their own complete HTML page without affecting the content loaded in the rest of the browser. You can hide a frame by using CSS and use JavaScript to dynamically load content into the hidden frame without the user's knowing. A <frame> tag must be declared inside a <frameset>, which replaces the <html> tags. A <frameset> does not display any content itself; its nested frames do. In contrast, an <iframe> can be placed anywhere between the <body> tags, and so it becomes embedded in the content of the HTML page. The <iframe> tag has become more popular than the <frame> tag partially because when the code uses a <frameset> the browser's location bar points to the URL of the <frameset> instead of the URL of the content actually being viewed by the user, which prevents the user from bookmarking the page.

A limitation of the XMLHttpRequest object is that you cannot use it to upload a file. Web developers typically handle file upload by using the tag <input type=“file”/>. The browser renders an input field and a button for this tag that, when selected, displays the operating system's file selection dialog for the user to select the file to be uploaded. After the user has selected a file, all you have to do is submit the form and the browser handles sending the data to the web server for you. Unfortunately, for security reasons, browsers do not allow you to access the file system from JavaScript, and XMLHttpRequest does not have a feature to do this for you. So the only alternative is to use a hidden frame.

Listing 5.2.7

Using setTimeout() and abort() to Time Out a Request



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.