Is it possible to include a php file in a <noscr开发者_StackOverflow社区ipt>
tag ?......to show if javascript is disabled?
The simplest way to include a PHP file if no JavaScript was enabled would probably be this:
<noscript><iframe src="your_php_file.php"></iframe></noscript>
(not sure if I would use that myself though)
It is not possible for your server-side PHP code to find out whether Javascript is disabled.
If you put PHP code inside a <noscript>
tag, it will always execute, whether Javascript is enabled or not. However, the code's output will only be visible if Javascript is disabled.
You might want to use Javascript to redirect to a separate page.
Let me suggest that you read my answer here. It explains how PHP actually works. The PHP code is ran before the browser ever gets it.
A request works like this
Browser Asks for a Webpage
The Web Server Runs the PHP Code
The web server looks through the file that it is about to send to the browser and looks for PHP code. It then interprets the PHP code and makes a page.
The Browser Reads the Output
The browser reads through the HTML and Javascript code that is outputted by the webserver
PHP is never actually ran on the browser, so it has no idea about the prescence of Javascript.
精彩评论