Questions around usage of JavaScript.
<script> vs. <SCRIPT>
Symptom: Some customers experience JavaScript problems when a URL to a file with the script was defined with the <SCRIPT>
tag written in CAPITALS. The .JS file was successfully transfered into the browser cache, but the script could not be executed and the file appeared to be empty in JavaScript Debugger.
Example: <SCRIPT src="/sap/bc/bsp/sap/test/myscript.js" TYPE="text/javascript"></SCRIPT>
Solution: It is recommended to use lowercase letters for the <script>
tag and attributes. For the example above, after replacing the uppercase letters by lowercase ones the JavaScript worked as expected: <script src="/sap/bc/bsp/sap/test/myscript.js" type="text/javascript"></script>
.
<script language="JavaScriptN.N">
The language
attribute of the <script>
tag was deprecated in HTML 4.01 and should not be used. Using this attribute may result in errors (<script language="JavaScript1.2">
). Use the type
attribute instead: <script type="text/javascript">
.
Debugging JavaScript
Not a lot of debugging tools out there. Depending on your Web browsers, you will turn to Ms Script Debugger for Internet Explorer or Venkman for Firefox.
Nevertheless, you often only need to have a peek on what is inside a variable. Instead of a goold old 'alert', you can use this wonderful script from Shuns (http://www.netgrow.com.au/files/javascript_dump.cfm) who only requires that you add a mention in your pages.
Here is a screenshot from the author's web site:
|
|
|
|
|
|
|
|
|
|
|
|
|
Usage in BSP - Example:
<htmlb:content design="design2003" >
<htmlb:document>
<htmlb:documentHead>
<htmlb:headInclude/>
<%-- Some utilities to help debug Javascript --%>
<script src="Dump_src.js" type="text/javascript"></script>
</htmlb:documentHead>
<htmlb:documentBody scrolling = "no">
<htmlb:form id = "param_form">
<htmlb:link id = "link"
reference = "http://www.google.fr"
target = "_blank"
text = "Google" />
</htmlb:form>
<script type="text/javascript">
dump(document.getElementById("link").style);
</script>
</htmlb:documentBody>
</htmlb:document>
</htmlb:content>