使用$ doc-> addScript使用async =“ true”添加JavaScript


9

有可能使用addScriptwith async="true"吗?

我发现了一个使用一些巧妙的引号来欺骗嵌入功能的黑客,但似乎这可能是一个本机功能:

$doc->addScript("//myscript.js", 'text/javascript" async="true');

Answers:


10

如果您查看Joomla addScript函数,它将显示以下内容:

public function addScript($url, $type = "text/javascript", $defer = false, $async = false)
{
    $this->_scripts[$url]['mime'] = $type;
    $this->_scripts[$url]['defer'] = $defer;
    $this->_scripts[$url]['async'] = $async;

    return $this;
}

$async 是布尔值,因此以下内容应为您工作:

$doc->addScript('//myscript.js', 'text/javascript', false, true);

false$defertrue$async


-抱歉,您输错了
webchun
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.