dqybeh2884 2008-12-15 12:18
浏览 28
已采纳

javascript函数行为不正常

I have this little function

function makewindows(){
child1 = window.open ("about:blank");
child1.document.write("<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']), ENT_QUOTES); ?>");
child1.document.close(); 
}

Which whatever I try, simply outputs the php code as the html source, and not the result of the php code. This was previously working fine, and I am not sure what I have changed to result in this behavior.

I have pasted all the code now. An error is generated by a link that calls updateByQuery, preventing makewindows from being parsed correctly..I think. I am not sure what is wrong with updateByQuery however:

function updateByQuery(layer, query) {
   url = "get_records.php?cmd=GetRecordSet&query="+query+"&sid="+Math.random();
   update(layer, url);
}
  • 写回答

5条回答 默认 最新

  • duanjianao0592 2008-12-15 12:34
    关注

    I assume you still have it in a file that is parsed by PHP, like the others already have said. Then it is probably something above this code snippet that confuses the php-parser so it don't recognize the php-tag.

    To test that, try to output something else before this function, maybe just a comment or something.

    Also, use "var" before client1, or else client1 will be in the global scope.

    update 1 Since you tried to insert a piece of php-code and it broke, then the problem is that the server don't parse the file as it should.

    To test if the server really parses your .js files (its not the default setting I believe), create a new file: test.js

    <?php echo "This is a test"; ?>
    

    Open the test.js file in your browser and look at the page source. If it has the php tags your server don't parse .js files.

    update 2 If the php works in .js files, try to rewrite the function like this (sorry I have not tested it because I don't have access to a php-server right now)

    <?php    
    echo "function makewindows(){var child1 = window.open (\"about:blank\"); " .
    "child1.document.write(\"" . htmlspecialchars(json_encode($row2['ARTICLE_DESC']), ENT_QUOTES) . "\");" . "child1.document.close(); }";    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题