Java Scrip #2
Use multiple submit buttons on one form
Get the client IP
address
Hide a Frame
Use a JAVASCRIPT
username/password instead the browser's one
Protect a page
access with JAVASCRIPT only
Close a window after
a timeout
Emit a beep
Play a sound
Make a window close
itself after a delay
Use an apostrophe
(') in the window status
Send the FORM
response to another FRAME
Convert from type X
to type Y
Have your own error
message
Force a reload
Get the user
language
Initialize a SELECT
"on the fly"
Use multiple submit buttons on one form
Get the client IP address
Hide a Frame
The Frame "scriptFrame" will be invisible. Javascript in the scriptFrame can
be referenced with "window.parent.scriptFrame". That's an easy way to hide your
scripts from the user.
Use a JAVASCRIPT username/password instead the browser's one
URL can be constructed with a special syntax to include an username and password. The
format is username:[email protected]. The URL is protected using the
mechanism included with the web server.
User: | |
Password: | |
Protect
a page access with JAVASCRIPT only
If the password protection mechanism provided by the Web server is not available, a simple
way to protect a page with JAVASCRIPT is to match the user password with the filename to
be loaded.
Password: | |
Close
a window after a timeout
This will open a window using the welcome.html file. The window will close itself
after 5 seconds.
|
Emit
a beep
The only way to make a "System Beep" with Javascript is to call the JAVA beep()
function (available in JDK1.1).
Make
a window close itself after a delay
Use an apostrophe (') in the window status
Simply use the escape character.
window.status='Welcome to Real\'s Home'; |
Send the FORM response to another FRAME
To send the result of a FORM request to another FRAME, you provide the FRAME name in the
target property of the FORM. The FRAME name is the one defined by the NAME parameter in
the FRAME declaration. The name must be unique.
[main HTML (a.html)]
[f1.html]
Convert from type X to type Y
A string to integer
s = "12"; i = parseInt(s, 10); or i = eval(s) or i = s - 0; |
An integer to a string
i = 12; s = (i).toString(); or s = "" + i; (hex string) s = "0x" + (i).toString(16); (oct string) s = "0" + (i).toString(8); (bin string) s = (i).toString(2); |
dummyDate = new Date() ; dummyParameter = "?" + dummyDate.getTime() self.location.href = "myPage.html" + "?" + dummyParameter |
Get the user language
For Netscape, use navigator.language
For IEv4, it's navigator.browserLanguage or navigator.userLanguage
language = "" if (navigator.language) language = navigator.language; if (navigator.browserLanguage) language = navigator.browserLanguage; if (language == "") language = "en"; else language = language.substring(0,2); if (language=="fr") document.write("Bonjour le monde"); else document.write("Hello World"); |
Initialize a SELECT "on the fly"
12/04/99