joomla在onBeforeCompileHead函数中获取内容

I'm developing a Joomla system plugin. I need to add javascript and css files if the certain [myshortcode] shortcode found in content.

How can I get the content in onBeforeCompileHead function

 function onBeforeCompileHead() {
        $document = JFactory::getDocument();
        //add scripts only if shortcode found
        ...
        $document->addStyleSheet($cssFile, 'text/css', null, array());

The $content = JResponse::getBody(); does not work.

Thanks

Try this,

For style sheet,

$document = JFactory::getDocument();
$document->addStyleSheet('http://domain.com/templates/css/style.css');

For Javascript File

 $document = JFactory::getDocument();
 $document->addScript('full url');

Also you can do like this,

$document = JFactory::getDocument();

// Add Javascript
$document->addScriptDeclaration('
    window.event("domready", function() {
        alert("An inline JavaScript Declaration");
    });
');

// Add styles
$style = 'body {'
        . 'background: #00ff00;'
        . 'color: rgb(0,0,255);'
        . '}'; 
$document->addStyleDeclaration($style);

If this case any jQuery issue you can try addCustomTag option too like here

Hope its helps..