> > I want to improve this by preg_match_replace-ing the whole page output. > The solution to your problem isn't using output buffering to generate a lot of obtrusive JavaScript. Have you considered unobtrusive JavaScript? That would rather clearly make the most sense here.