我如何检查某些文本是否使用PHP输出到屏幕上?
例如,我的代码是:
<html>
<body>
<noscript>
error: no js
<noscript>
<?php
//detect if the HTML printed out "error: no js"
?>
</body>
</html>
我想检测HTML是否打印出指定的<noscript>
消息。这可以用PHP或在PHP页面上实现吗?如果JavaScript被禁用,或者输出了某些输出,是否有更好的方法来停止任何脚本?
我特别想这样做,因为如果满足某些条件,我可以传递某些输出,并让PHP根据输出进行操作。
谢谢!
我唯一能想到的就是设置一个cookie:
<script type="text/javascript">
document.cookie = "jsEnabled=true";
</script>
然后,你可以在PHP中做一个简单的检查:
<?php
if (isset($_COOKIE['jsEnabled'])) {
// Javascript is enabled!
} else {
// Javascript is not enabled!
}