SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Too many characters in a JavaScript function?

    In IE, it looks like you can have to many characters in a javascript function.

    The content of an entire html page is put into this function...

    Code:
    function updateTemplate(content) {
        content=content.replace(/\\\'/g, '\'');
        content=content.replace(/\\\"/g, '\"');
        content=content.replace(/&lt;/g, '<');
        content=content.replace(/&gt;/g, '>');
        Element.update('template',content);
    }
    it seems to cut off the content after about 2060 characters. is that an IE thing or is there something wrong with my code. FF does it fine...

    If it is an IE thing, is there anyway around it?

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check your code. Look at any difference in the content string between the browsers.

  3. #3
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mrhoo View Post
    Check your code. Look at any difference in the content string between the browsers.
    Thanks for that. The only difference I've found is FF allows unlimited (or a lot more characters) as the content string and IE only allows 2060 characters...

    Anything else I should look for? Do you think it is a browser thing or is there something I am missing?

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know that if there is a limit, you are nowhere near it. It is not unusual to transmit JSON libraries, which are constructor functions, of 100000 bytes with javascript. What I would look for is a newline or null character, or a trailing comma in an object constructor. Something different in the two browsers interpretation of the string.

  5. #5
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, that's a good idea! I hope that's it as that will save me a lot of hassle Thanks mate!

  6. #6
    SitePoint Evangelist Mr. Tech's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea! I found out what was causing it... It was a \0

    "\0" (ASCII 0 (0x00)), the NUL-byte.
    I simply used the trim() function in PHP to remove it.

    Thanks for your help! Couldn't have done it without ya!

  7. #7
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad you found it. It can be a beast to track down those string wrecking bytes.


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
  •