doulai8128 2016-03-27 17:28
浏览 39

将PHP变量发送到Javascript而不影响“查看源代码”

I'm creating variables through PHP and sending them to Javascript by echo'ing them, then using document.getElementById in JS to grab their values.

The problem with this I have realized is that the elements I am writing with their their php variables are being shown when anyone views the source. It's not behaving like JS where I can write HTML and nothing gets shown on the source (using document.write for example).

How can I send variables from PHP to JS without affecting the viewable source like JS does?

  • 写回答

1条回答 默认 最新

  • douzhoulei8959 2016-03-27 17:51
    关注

    If you want it to behave like JavaScript, you can echo <script> [insert javascript] </script> and write document.write or whatever you choose inside those tags.

    However, there is no way for you to keep it hidden if someone really wants to find out what is happening. HTML and JavaScript are both front-end. Your server is not doing anything at all when it comes to rendering HTML and executing JavaScript; it is all done by the user. And if the user is doing the calculations, the user also knows what is happening.

    I do not see why you would want the HTML to be hidden anyway. Even if one cannot see the source code of HTML, one can still figure out more or less how to replicate what you have done (if the purpose of this is to keep the design a secret).

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100