Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript document.write()在wordpress header.php中不起作用_Javascript_Php_Wordpress - Fatal编程技术网

Javascript document.write()在wordpress header.php中不起作用

Javascript document.write()在wordpress header.php中不起作用,javascript,php,wordpress,Javascript,Php,Wordpress,执行document.write()的javascript函数在WordPress帖子正文中调用时可以正常工作,但在WordPress的header.php模板中调用时不起任何作用 关于如何让document.write()在WordPress的header.php中工作,有什么建议吗 switchads();包含document.write()命令。 函数在header.php中调用,但document.write()不会对页面产生任何更改 此代码段显示了如何在header.php中调用函数(

执行document.write()的javascript函数在WordPress帖子正文中调用时可以正常工作,但在WordPress的header.php模板中调用时不起任何作用

关于如何让document.write()在WordPress的header.php中工作,有什么建议吗

switchads();包含document.write()命令。 函数在header.php中调用,但document.write()不会对页面产生任何更改

此代码段显示了如何在header.php中调用函数(位于adtest.js中),并且它不会输出HTML(在文章正文中,它会输出):


正在调用的javascript函数包含一个文档。write():

函数开关ads(){
document.write(
“此处随机html”
);
}

您检查过控制台了吗?有什么错误吗?您是否运行了adblocker?很长一段时间以来,没有必要使用CDATA块保护脚本。首先,让我们在
文档下添加一个
控制台。记录
。编写
以确保您的代码实际运行。
        <div id="ad1">
            <script type="text/javascript" src="adtest.js"></script>
            <script type="text/javascript">
            <!--//--><![CDATA[//><!--
            switchads();
            //--><!]]></script>
        </div>
function switchads() {
  document.write (
    '<div>random html here</div>'
  );
}