SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript innerHTML converting &reg into

    We have a link checker application that has been running for over a year and we just ran into a problem.

    There is a new piece of a "http://" link string that is: &region= When the variable that contains the http string is converted to the page using innerHTML a piece of the string &reg turns into the symbol even though it is not followed by a ; character.

    Has anyone ever run into this behavior and if so, is ther a fix or hack for it?

    Thanks for reading.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Never seen that before. Have you tried splitting it? I.e.:
    Code:
    something.innerHTML = 'http://www.example.com/index.html?name=bob&r' + 'egion=';

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2007
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or turning the & into & like it should be?

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2005
    Posts
    436
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change the variable. The same thing just happened to me with &part

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    & has a special meaning in HTML - it defines the start of an entity code. Where you want a real & you specify it as & which is the entity code for a &.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •