Placing the JavaScript Block
This is not really an advanced
topic, but it helps the guys who recently jumped in Web development Bus!
Usually the content in HTML
document is processed in linear approach in the order in which it appears, from
top to bottom. If you have any script block that uses immediate JavaScript code
[the raw script statements which are not wrapped in a function) is executes as
soon as it is processed. So, to avoid such problems you must place script
blocks after any elements that it manipulates.
However if your script blocks
wrapped inside function/uses functions that are called later in the page life
cycle (e.g. event handling functions that are triggered in response to a
client-side event) cool guys! You don’t need to worry. In this situation, the
browser will process the entire page before your functions are triggered. As a
result, you can place your script block anywhere in the HTML document! It’s
your area, your rule! But, according to me <head > section is the popular
choice.
I know developers are like Heroes,
But please stop behaving like James Bond!!
Placing JavaScript in a separate file or even
embedding it in an assembly doesn’t prevent users retrieving it and examining
it (my Friend Sowmya always do it, whenever she found an interesting JavaScript,
she’ll save it directly and starts modifying it. Just kidding! But it’s a fact)
and even modifying their local copy of the webpage to use a tampered version of
the script file. Therefore, you should never include any secrete algorithms or
sensitive information in your JavaScript code. You should also make sure you
repeat any JavaScript validation steps on the server because the user can
circumvent client-side code
Debugging JavaScript
Visual Studio has an integrated
JavaScript debugging. If you are using IE 8, you don’t need to take any steps
to switch on client-side debugging. Visual studio sets it up automatically,
regardless of your Internet Explorer settings
Oops! What about older version of
IE?
With versions of IE 8, you need
to explicitly enable script debugging. To do so follow these steps
- Choose Tools > Internet Options from the menu in IE
- In the Internet Options dialog box, choose the advanced tab
- In the list of settings, under the Browsing group, remove the check mark next to Disable Script Debugging (IE). You can also remove the check mark next to Disable Script Debugging (Other) to allow debugging for IE windows hosted in other applications
- Click Ok to apply your changes
When script debugging is switched
on, you’ll be prompted to debug web pages with script errors, even on websites
that you don’t control, even on Google too! (But I’m dam sure; they don’t have
any script errors)
No comments:
Post a Comment