Passing Identifiers to Javascript
Posted: Thu Nov 16, 2006 10:46 am
Been working on a project that handles users comments on HTML pages, a drop-in Javascript. I need to pass a unique identifier for each HTML page to the Javascript. I figure I can pass this ID the following ways ...
- Hard coded in-line Javascript
PROS: Simple. Standard.
Code: Select all
<script type="text/javascript"> var pid = 1; //Page ID </script>
CONS: ? - Via the script source URL
PROS: ?
Code: Select all
<script type="text/javascript" src="/javascripts/nifty.js?pid=1"></script>
CONS: Need to dynamically generate the Javascript. Caching? - Via the URL for HTML
PROS: ?
Code: Select all
http://www.domain.com/rant_about_programming_number_94.html?pid=1
CONS: Passed via GET. Easily messed with by users. Screws up a pretty simple URL scheme. - Via Meta Tags
PROS: Sort of the purpose of Meta tags, indexing. No in-line Javascript just to set a variable.
Code: Select all
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=US-ASCII"> <meta name="keywords" content="programming rant"> <meta name="description" content="Just the rantings of a senile old programmer."> <meta name="author" content="Buddha"> <meta name="published" content="Tue, 14 Nov 2006 16:20:12 +0000"> <meta name="updated" content="Tue, 16 Nov 2006 18:36:18 +0000"> <meta name="pageID" content="1">
CONS: May effect SEO? Never seen Meta tags used this way.