Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete specific data from html

    I have been struggling with finding a solution for this problem for a few days, and being unfamiliar with scripting for the most part, I was hoping someone here may be able to point me in the right direction.

    I setup a simple Moblog through blogger.com to record an upcoming roadtrip, and relized that my cellphone provider (Verizon) adds in some marketing blurb to evey MMS I send. This creates a mess of text and <br /> tags that I want to get rid of without having to log in and manually edit the code.

    I assumed DOM scripting would be the easiest bet, to just point it to the element, check that the text string was present and if so, delete the parentnode of that text string. Unfortunetly, I can not find any information about someone dong this before, so I am stuck.

    Here is the page I was testing with.

    Obviously, I want the script to look at the page onLoad and if it sees a text node with the specified text, to delete that node and leave only my original caption.

    Thanks in advance if you can point me in a direction to look or have any ideas.

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    I would try always starting your messages with a special character, like _ or !

    then:
    Code:
    var msgs = document.getElementsByTagName("P");
    
    for (var i = msgs.length -1; i >= 0; --i)
    {
      if (msgs[i].className == "mobile-post")
      {
         if (msgs.firstChild.nodeValue.charAt(0) != "_")
           msgs[i].parentNode.removeChild(msgs[i]);
      }
    }
    You do realize though that as you add more and more to your blog that this will take more and more time, right?

  • #3
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the quick reply, I will give that a shot.

    I do realize that it will start to take longer and longer the more posts I add. I just want to have it there as a preliminary edit until I can get to a computer and go in and edit out the offending lines manually. That way my family can view pictures of my trip, without having to wade through post after post of verizon spam.

  • #4
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm, Well I tried what you suggeted, but it doesn't seem to want to do anything. Maybe I am missing something.

    Heres the sample page again: Test Page

    Any feedback would be appreciated.

  • #5
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    wrap the script in a function and call it onload.

    Your currently running the script before the paragraphs are even there, so nothing happens.

  • #6
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm sorry, I am just not getting it. I have tried a bunch of things, and the closest I got was when I left the </script> tag off the end and none of the page displayed (boy, was I excited!).

    If you could find it in your heart to look at this once more and tell me what an obvious idiot I am being, I would appreciate it.

    http://www.platypie.com/test.htm

  • #7
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    1) function remove() {

    2) <body onload="remove();">

    3) Scrap the bottom script block

    4) If it doesn't work from there, then my code is slightly off, you should put an alert in to see what the value of charAt(0) is, try to figure out what's going on by alerting various values throughout the code to make sure your logic is working.

  • #8
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Beagle, thanks your brilliant!

    I finally realized where the trouble was.

    Code:
    var msgs = document.getElementsByTagName("P");
    
    for (var i = msgs.length -1; i >= 0; --i)
    {
      if (msgs[i].className == "mobile-post")
      {
         if (msgs[i].firstChild.nodeValue.charAt(0) != "_")
           msgs[i].parentNode.removeChild(msgs[i]);
      }
    }
    You had left that off the original sample(on purpose maybe?), and after playing with alerts for a couple minutes, it was glaringly obvious where it was going wrong. Thanks so much for your help, I learned alot!

  • #9
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    I just double checked my original post, and you're absolutely right. I did make an error and I apologize for it. However, I'm glad that you learned a lot. It's always better that you learn something, that way you can acheive more. I hope you enjoy your trip!


  •  

    Posting Permissions

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