javascript confirmation with html character code

#1
[eluser]Jagar[/eluser]
I know this has nothing to do with CI, but I hope somebody knows the answer.

Admins have a list of all the items they have added, and trying to make everything as safe as possible, the only think that is not working is the javascript confirmation, such as the following:

Code:
return confirm('Are you sure you wish to delete Don't be sad?');"

That is attached to a link when the user clicks on it, they will get that confirmation, but in this case that character ' is the single quote, so it shouldn't be a problem with javascript since it's safe. But it is not, when items such as that with single quote, gets clicked, the user does not get a confirmation, but it gets deleted right away,

Is there any way around this?

Thanks

#2
[eluser]drewbee[/eluser]
Even though it is an entity, javascript still interprets it as a single quote. You still need to make sure you are escaping the entity version of it with a backslash.

Code:
var string = 'ampersand & woot & and &<';
    string = string.replace(/&/gi,'\&');
    alert(string);

#3
[eluser]Jagar[/eluser]
Thanks for the reply, that will solve the problem.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.