Put your text ad here
WestNIC provides reliable web hosting services
Free software downloads and drivers download resources
Top Canadian Hotels no booking fees from Victoria BC to Nova Scotia
This FAQ is part of the Code Style Help and FAQ section. Join our premium content service for full access all FAQ answers.
A: You are strongly recommended to use CSS to achieve your print requirements, it is much better suited to this task and is more likely to be enabled in the users' browser. See the Media dependent style sheets FAQ for full details.
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: The answer to this question depends on the medium you use for your text output. If you want to raise a Javascript alert, confirm or prompt containing Arabic, you must use a Unicode escape sequence: a back slash followed by a lower case letter u and a 4 digit hexadecimal number for the Unicode code point, as in the example below:
… premium content omitted
Access all premium content for $50: sign-up now.
How can I write Arabic characters in my Javascript?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: Yes, it is possible to get the referring search engine query, if the browser exposes the document.referrer property, which is the URL of a page that links to the current page. For security reasons, some browsers allow users to control whether referring page information is available. The complete example below solves several significant technical and other security issues to obtain a clean, plain text copy of the original keyword phrase:
… premium content omitted
Access all premium content for $50: sign-up now.
Can I use Javascript to get entrance keywords from a search engine?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: To create robust logical redirection for the Web you should use server side techniques. An example confirmation form is included in the noscript fallback for the main Javascript implementation detailed below.
… premium content omitted
Access all premium content for $50: sign-up now.
How can I redirect based on a confirm response?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: Generally, it is better to use server side redirection using the HTTP 301 (moved permanently), 302 (found) or 303 (see other) status codes. These mechanisms should maintain appropriate back navigation with most common browsers.
… premium content omitted
Access all premium content for $50: sign-up now.
How do I make sure redirects have the right "back" page?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: This really depends how you have set the quiz up in the first place, but you could redirect the contestant to a results page and append the cumulative score variable to the query part of the URL...
… premium content omitted
Access all premium content for $50: sign-up now.
How can I generate a quiz results page?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: The URL of the current page is represented by the Javascript window.location object. There are several components to the location object that represent parts of the URL. The relative URL of the page is given by the location.pathname property, plus any query or "search" part and fragment identifier or "hash". Not all URLs include a query and fragment identifier, so these properties may be null and need to be checked, as below.
… premium content omitted
Access all premium content for $50: sign-up now.
How can I get the relative URL of a page?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: The usual way to invoke a script without a direct user action is to attach a function to the browser window's onload event handler. This event occurs when an HTML document is fully loaded and will automatically call your function. There are two ways to declare an onload event handler: add an onload attribute to the body element of the HTML, or assign the function in your Javascript, as below.
... <body onload="myFunction();"> ...
window.onload = myFunction;
Either approach will be sufficient. Don't use both or one will override the other.
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: The most important thing about using timeouts is to create a global variable, a “handle”, by which you can clear the timeout if you need to. The example below defines two functions delayAction() that sets the timeout to execute in 500 milliseconds and cancelAction() which aborts the action. The script inserts two action buttons into the page to trigger these function calls.
… premium content omitted
Access all premium content for $50: sign-up now.
How should I write a script using timeouts?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: Since Perl code is executed on the server side, you need to submit an HTTP request to your Perl script that indicates whether Javascript is enabled on the client side. You could do this by dynamically writing the variable to a hyperlink URL, or perhaps a hidden form field, as below.
… premium content omitted
Access all premium content for $50: sign-up now.
How can I check if Javascript is enabled in my Perl script?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: This script sets a simple boolean variable called enabled when the page loads. A function called disable() is attached to an onclick event handler on the first image button, and an enable() function is attached to the second. The script includes alerts that notify the state of the system.
… premium content omitted
Access all premium content for $50: sign-up now.
How can I toggle button images to enable and disable them?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: If you are the author of the HTML code, then you control whether there is any Javascript in the document in the first place. If you want Javascript to run to start with, then stop functions from working later, you can set a boolean property that controls whether the functions execute or not, as below.
… premium content omitted
Access all premium content for $50: sign-up now.
Is there a way to turn Javascript off in the HTML code?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: It is possible to check for Latin 1 characters using Javascript, though the usual conditions apply; if Javascript is not enabled, no check will be made, so it is better to do this kind of thing on the server side, or double-up with both.
One relatively simple way to check for non-Latin characters would be to define a single string that contains all valid Latin 1 characters. Loop through each character in the input string and check it is in the reference string. The working example below includes utilities to generate the reference character set and non-Latin characters to test.
… premium content omitted
Access all premium content for $50: sign-up now.
Is it possible to filter non-Latin 1 characters?
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: Client side Javascript cannot be used to provide secure authentication for Web sites because all the code would be accessible to users. Anyone with a reasonable knowledge of Javascript could use the source code to decrypt the authentication details and gain access.
A robust authentication system can only be implemented using server side techniques. Methods vary according to the Web server you use, but lots of pointers are available from Google, search for HTTP authentication.
Actions: Follow-up, clarify or correct this answer. Submit a new question.
A: This is a big question and the answer has more to do with user experience than technical implementation; what tasks do users want to do with your user interface and how will it present itself to them? List out all the things users will want to do in priority order from their point of view, not yours. Use pen and paper to sketch out the user interface for each of these use cases independently of each other. What information will the user need? What input will they need to make? How will the system respond in the expected outcome and in error cases? Are there common elements amongst them? Re-draw the screens with common elements merged and separate tasks available in menus, tabs or buttons.
Show your design sketches to other people, ideally people who will use the system, to check and refine the interface and how it should behave. By testing with real users you can discover useful additions that you might not have thought of.
Once you have final sketches for the interface, build it as a separate series of pages in standard HTML and CSS first. It is far easier to test and refine your design and layout in hard code than re-generate code using Javascript. You may find find this format will work well enough for people with Javascript switched off.
Again, show your HTML pages to end users and get feedback before transcribing the markup to Javascript. As far as possible use the static HTML as the basis of your application and enhance its behaviour with Javascript. You may find that Javascript event handlers for specific actions will improve performance without re-generating the whole user interface using Javascript.
Actions: Follow-up, clarify or correct this answer. Submit a new question.
| Front-end FAQs | Back-end FAQs | Learning Java |
|---|---|---|
About us: site help, text ads and premium content FAQs.