views:

185

answers:

2

Hi Guys, I have a js script on my blog page that scans the page, looks for special snippets similar to bb code and translates it into an image. For example, i search for all instances of [ ] and replace it with a box image, or all images of :) and replace it with a smiley.

I also have a live preview script for my comments. My problem is that in my live preview DIV, if the user uses :) or [ ] it won't turn them into images since this .js file only scans the page after it loads. Is there a jquery or javascript command I can do to have it run this script again and analyze this live preview DIV ?

cheers for any aide

A: 

you could use setInterval to run a javascript function every x seconds and looks for things to replace, or you could check on the keyup event.

function analyzePage()
{
    // do analyze page stuff here
}

$(document).ready(function()
{
    // cause analyzePage(); to be called every 2000 milliseconds
    setInterval(function(){ analyzePage(); }, 2000);

});
John Boker
This is a pretty hacky way to do it.
rpflo
@rpflo , how would you do it?
John Boker
+1  A: 

The same code that updates the contents of the live preview div should also call your "replace" function. To keep things speedy, you can direct the function to scan only the contents of the live preview div, and not the whole page.

zooglash