dounie0889 2012-03-28 10:55
浏览 42

为什么PHP无法进入本地存储?

Why is it that in php you can open up a script tag like so and do the following:

<?php
  print("<script>");
  print("alert('hey');");
  print("</script>");
?>

but you can't do this:

<?php 
  print("<script>");
  print("document.getElementById('fName').value = localStorage.getItem('FirstName');");
  print("</script>"); 
?>

I just can't understand what the difference is, if you can get javascript to work inside php, why can't you tap into localstorage?

  • 写回答

3条回答 默认 最新

  • dongnaizao8039 2012-03-28 11:03
    关注

    There is no dependency on the content of the Javascript. PHP does not "filter" your output and your browser won't recognize that it has been the output of a PHP script.

    Does the script work if you don't output it that way and instead write it statically into your document? Please note that the script does not automatically add line breaks and possibly procudes invalid Javascript code if you forget the semicolon.

    Can you paste the output of your browser's error console?

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比