SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2004
    Location
    UK
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Isd there an Alternative to Replace() function in javascript

    Hello i am developing an advanced ebay store and listing and would like to use jquery with it. Now i want to stay well in ebays rules and use javascript that they have deamed safe. I know of 2 ways of bypassing there detection script to use code that they have banned but i dont want to do this and stick to the rules incase they see my listing and ban me or someone or a competitor reports me.

    At present ebay has banned these functions - javascript (".cookie", "cookie(", "replace(", IFRAME, META, or includes), cookies or base href.
    now the standard Jquery application has replace() all over it. My question is - is there another javascript function i could use in place of Replace() in jquery and i will just go through it and add the new function in place of Replace()? Or can i create a new function in pure javascript to replicate the replace() functionality

    Kind regards

  2. #2
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    Posts
    387
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Just off the top of my head, you could split a string based on the old value and join it again with the new value. Something like this:

    Code JavaScript:
    function fakeReplace(str, substr, newstr) {
        return str.split(substr).join(newstr);
    }

    Obviously, there are some pretty big caveats:

    • You can't use regular expressions.
    • It's case sensitive.
    • I have no idea how you could integrate this into jQuery, other than changing every single "replace" reference.
    I'm the web overlord for Graphic Business Systems

  3. #3
    SitePoint Member
    Join Date
    Sep 2004
    Location
    UK
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sdleihssirhc View Post
    Just off the top of my head, you could split a string based on the old value and join it again with the new value. Something like this:

    Code JavaScript:
    function fakeReplace(str, substr, newstr) {
        return str.split(substr).join(newstr);
    }

    Obviously, there are some pretty big caveats:
    • You can't use regular expressions.
    • It's case sensitive.
    • I have no idea how you could integrate this into jQuery, other than changing every single "replace" reference.
    Thanks sdleihssirhc for your reply. After some research in other places i also came to the realisation that i could use your solution but i think it should work with regular expressions i just did this to test it and it worked and other places have said regular expresions work with split.

    Code javascript:
    var str="00 000 00 000 00 000";
    var patt1=/\d{3}/g;
    str = str.split(patt1).join("111"); 
    document.write(str);

    Thanks for your help i'm now going to change every "replace()" ref in the jquery code and see if its still works. there is 60 uses of it in the code base. it may slow it up some as replace is much quicker than split join, but hopefully it wont be that noticeable. Thanks


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
  •