如果没有javascript,而是使用php而不是< noscript&gt ;,如何防止页面加载? [英] How can I prevent a page from loading if there is no javascript, but using php instead of <noscript>?

查看:107
本文介绍了如果没有javascript,而是使用php而不是< noscript&gt ;,如何防止页面加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中有一个包含php和其他内容的页面.我需要做的是一种使用php检查浏览器中是否启用了javascript的方法. 这样,将阻止整个页面源的加载,而不是使用这样做,只能阻止页面的加载,但允许源代码.

I have a page with php and other stuff in the code. What I need to do is a way to check with php if there is javascript enabled in the browser. This way, the whole page source will be prevented to be loaded, instead of using that only prevents the page from loading, but allows the source code.

推荐答案

PHP是服务器端语言.由于PHP在服务器上运行,因此无法将其执行,然后将结果发送到客户端.服务器不知道客户端是否启用了JavaScript.

PHP is a server-side language. There is no way to do this with PHP since it is run on the server, and then the result is sent to the client. The server has no knowledge of whether the client has JavaScript enabled or not.

如果禁用JS时不想在.html文件中显示代码,则不必使用PHP.您可以将必要的内容放入.html文件,然后使用JavaScript加载其余内容.如果禁用了JavaScript,则其余所有内容都不会首先加载. (这称为渐进增强.)

If you don't want to show the code in your .html file when JS is disabled, then you don't have to use PHP. You could put the essential stuff in the .html file and load the rest in with JavaScript. If JavaScript is disabled, the rest of the stuff never gets loaded in the first place. (This is called progressive enhancement.)

这篇关于如果没有javascript,而是使用php而不是< noscript&gt ;,如何防止页面加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆