/    Sign up×
Community /Pin to ProfileBookmark

Hey…
look how can i decode all html entities (& < etc) from the innerHTML of some element..?
for example, I’ve got this:

[code=html]
text = ‘<a href=”index.php?a=1&b=2″>link</a>’;
MM_findObj(‘element’).innerHTML=text;
[/code]

but the link will not work as it’s expected…
<a href=”index.php?a=1&amp;b=2″>link</a>

any ideas..?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@methodpgDec 29.2005 — What happens if you change:

[CODE]MM_findObj('element').innerHTML=text;[/CODE]

to...

[CODE]document.getElementById('elementIDGoesHere').innerHTML=text;[/CODE]

replacing [i]elementIDGoesHere[/i] with the ID of an element on your page??

Only asking this in case the MM_findObj function is converting the content.

(Been a while since I relied on Macromedia's scripting)
Copy linkTweet thisAlerts:
@CrazyMerlinDec 29.2005 — links are parsed once they arrive at a script, the browser does not parse a link, and that is what you are trying to do.

it's like saying: <a href="index.php?a=1&#38b=2">link</a>

Can I ask the purpose of it?
Copy linkTweet thisAlerts:
@KorDec 29.2005 — try using unicode notation, as javascript usually decodes special characters.

text = '<a href="index.php?a=1[COLOR=Red]u0026[/COLOR]b=2">link</a>';
Copy linkTweet thisAlerts:
@delr2691authorDec 29.2005 — ohh i'll try using unicode notation....

It is not really a link what i'm trying to insert...

But an image <img src=img.php?id=123&op=2>

i'm generating dynamically the image with php [that's why the source is img.php]

the page gets the variables [id and op] passed by GET and then generates the image...

But as the & is being converted into &amp; PHP can just interpret that ID = "123&amp;op=2"

Hope you understand my poor explanation... ?
Copy linkTweet thisAlerts:
@delr2691authorDec 29.2005 — hmm... No... javascript still converts the u0026 into &amp;

but if i print the var text it is printed as it should... the problem is when it becomes the innerHTML of an element...
Copy linkTweet thisAlerts:
@delr2691authorDec 29.2005 — Is there a function in JavaScrip like html_entity_decode() in PHP.......??

I think that would work....
Copy linkTweet thisAlerts:
@delr2691authorDec 29.2005 — Never mind... problem solved...

I just changed the id=1&op=2

to id=1-2 and splited it...

tnx anyway... ?
×

Success!

Help @delr2691 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...