Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

innerHTML encoding? 1

Status
Not open for further replies.

vbkris

Programmer
Jan 20, 2003
5,994
IN
hi,
i have a div that has the following content:
Code:
<div name='Lnk'>
<a href='hello.asp?id=1&title=Title'>Title</a>
</div>

when i give the command:
Code:
content1=document.getElementsByName('Lnk').innerHTML
//content is something like this:
//<a href='hello.asp?id=1&amp;title='Title'...

ie it has encoded the & to &amp; in the query string. is there a function to take it back to &.

Note: i cannot use document.getElementId of the link.

thanks



Known is handfull, Unknown is worldfull
 
have you tried unescape?
Code:
content1 = unescape(document.getElementsByName('Lnk').innerHTML);

-kaht

banghead.gif
 
Surely as getElementsByName returns a collection, you should be using this:

Code:
content1 = document.getElementsByName('Lnk')[0].innerHTML

instead of this:

Code:
content1 = document.getElementsByName('Lnk').innerHTML

I don't know if it will make any difference or not, but it's something to try all the same ;o)

Hope this helps,
Dan

 
right in one...

Known is handfull, Unknown is worldfull
 

Strange - I thought that unescape was used for URL encoding (such as %20 for space, etc) - in fact, if I do this:

Code:
alert(unescape('abc&amp;def'));

I see this:

Code:
abc&amp;def

and not

Code:
abc&def

So am at a loss to work out why it's working for you.

How strange!

Dan

 
this gave me normal results:

Code:
alert(unescape('Hey&gt;asd'))

gave me Hey>asd

Known is handfull, Unknown is worldfull
 

Strange... I saved this as an HTML file:

Code:
<script type="text/javascript">
alert(unescape('Hey&gt;asd'));
</script>

An ran it in IE6 on Win XP Pro, and I see:

Code:
Hey&gt;asd

in the alert box.

Getting ever stranger ;o)

Dan
 
my browser is IE5 so unless there is a compatibility issue...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top