Results 1 to 3 of 3

Thread: Firefox HTML Code

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    24

    Firefox HTML Code

    Okay,

    So I have a script in Javascript, which basically puts a textbox on a popup.
    And then writes some text in it.

    e.g.

    HTML Code:
    <textarea cols=80 rows=10 onFocus='this.select()'>
    [img]justexthere&centrex=500moretextnow[/img]
    </textarea>
    However, my problem is that it changes the "&cent" to a HTML code of: ¢. Which I have no idea how to stop this, so can anyone tell me how please

  2. #2
    Addicted Member
    Join Date
    Feb 2010
    Location
    Damascus - Syria
    Posts
    145

    Re: Firefox HTML Code

    Hello

    That's because the browser will automatically use the HTML entities

    to solve this problem, you should give the '[img].....' like text plain using javascript, at the same time there are different ways according to the browser

    for firefox, use this script line:
    HTML Code:
    <script type="text/javascript">
    document.getElementById('textareaid').textContent = '[img]http://www.vbforums.com/[/img]';
    // textContent turned to innerText in IE
    </script>
    if you don't want to check the browser to define what property will you use, this has a solution too

    include jQuery and use the function text() like this way:

    HTML Code:
    <script type="text/javascript">
    $('#textareaid').text('[img]http://www.vbforums.com/[/img]').html();
    </script>
    regards

    Feras Jobeir
    Last edited by fjober; Aug 14th, 2011 at 04:37 PM.

  3. #3
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Firefox HTML Code

    Convert HTML entities:

    Code:
    function htmlEntities(str) {
        return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
    }
    Usage:
    Code:
    alert(htmlEntities("&centrex"));
    From CSS Tricks.
    Like Archer? Check out some Sterling Archer quotes.

Posting Permissions

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



Click Here to Expand Forum to Full Width