For full functionality of this site it is necessary to enable JavaScript.
Here are the instructions how to enable JavaScript in your web browser.

Knowledge base

Find the answer to your question

Advanced Search PView

Search terms
Search Type
Product
Category
Language
Format
SDK
Sort by
Direction

JavaScript best practices

  • Answer ID 53
  • Published 06/11/2004 04:45 PM
  • Updated 10/20/2013 06:40 AM
  • Permalink https://ebaydts.com/eBayKBDetails?KBid=53
Product
JavaScript best practices
The Description of an item is considered the key to making a profitable sale.
The careful use of JavaScript can help make an attractive Description leading to that profitable sale.
The ViewItem page which displays an item's description contains a good amount of JavaScript
developed by eBay.

The key to safe JavaScript in a description is to make sure you abide by some simple rules set forth here.

1. The following JavaScript constructs are not allowed in the Description:
".cookie"
"cookie("
"replace("
"open("
"eval("
"IFRAME"
"META"
"includes"
"cookies"

Attempting to list an item with any of these constructs will result in an error returned by the AddItem call, and of course the item will not get listed.

2. You cannot attempt to make use of any JavaScript developed by eBay. Specifically this means you cannot modify or reference JavaScript variables or JavaScript functions developed by eBay.

3. Another rule of thumb is to use good variable and function naming conventions. This is always a good software development practice, but it's all the more
important here, because you do not want your JavaScript to interact with the JavaScript already in the ViewItem page that is
developed by eBay. We recommend you follow these simple guidelines for naming variables and functions in JavaScript:
For naming variables, the first letter should denote the type of the variable. We will restrict this discussion to strings, numerical types, arrays and objects since JavaScript variables
can be safely categorized as such. Strings should start with "s", numerical types should start with "n", objects should start with "o", arrays should start with the letter indicating what this is an array of followed by the word "Array", and functions should start with "f".
You should try to keep this first letter lower case and the second letter upper case. Somewhere in each variable name or function name you should
have a 3 or 4 letter common identifier indicating your product or company or application. The number of letters you choose
is really up to you; this is just to keep a "namespace" convention in your JavaScript so that you can quickly identify functions and variables that belong to you. We have seen instances of Descriptions that had variable name conflicts with the standard eBay JavaScript.
As you can imagine, this led to both the Description not rendering as the user expected and the eBay functionality on the ViewItem page not working correctly (you certainly don't
want to break the ability to place a bid!).

Here's an example of a good variable name and function name for a fictional application called "AmazingLister"

sArrayAmazingShippingTerms
fAmazingPopulateShippingTerms(..)

Of course you can have your own conventions, so long as you remain consistent and reasonably unique you'll avoid this issue.

How well did this answer your question?

Answers others found helpful

Print Email This Page Delicious Digg Facebook Reddit StumbleUpon Twitter