Connecting Tech Pros Worldwide Forums | Help | Site Map

document.write('&timestamp') problem

Newbie
 
Join Date: Dec 2008
Posts: 1
#1: Dec 8 '08
I'm having an issue that I'm sure there is a simple fix for! I'm creating a java script that will dynamically create a URL. In the process I need to include a URL parameter '&timestamp=' followed by an actual timestamp. I noticed that when I use the combination &timestamp under IE 7 the string gets converted to xtamp. This even occurs if I just use document.write('&timestamp'); to write the string out. It results in xtamp! Under a firefox browser the string gets represented correctly.

Any insights would be greatly welcomed!!! Thx

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,654
#2: Dec 8 '08

re: document.write('&timestamp') problem


I'd recommend using the DOM methods instead of document.write(). for standard complient browsers this would be (creating the href-attribute)
Expand|Select|Wrap|Line Numbers
  1. element.setAttribute("href", "href_value");
but IE doesn't fully support that (at least as far as I know), so you need the older DOM methods:
Expand|Select|Wrap|Line Numbers
  1. var HR = document.createAttribute("href");
  2. HR.nodeValue = "href_value";
  3. element.setAttributeNode(HR);
and it's always good practice to escape the ampersand (xhtml parsers will give you an "undefined entity" error, otherwise).

regards
clain's Avatar
Member
 
Join Date: Feb 2007
Location: Chennai, INDIA
Posts: 68
#3: Dec 9 '08

re: document.write('&timestamp') problem


yeah... thats correct... IE renders all the time related DOM objects in old fashion. it needs to update the scripting engine. unfortunately they do not do so...

only alternate idea is to have a custom made time stamp.. its a hard task though.. there no other alternative (at least as far as i know)
Reply