سؤال

Is it correct and valid to use something like this:

<noscript>
<?php require_once 'somefile.php'; ?>
</noscript>

I've been searching for this answer a lot but unfortunately not much luck. Here is a quote from one of the answers by @SLaks on this page.

"If you put PHP code inside a tag, it will always execute, whether Javascript is enabled or not. However, the code's output will only be visible if Javascript is disabled."

However I am not very clear if it is valid to use php within a <noscript> tag.

هل كانت مفيدة؟

المحلول

PHP operates on a stream of text. It doesn't care what the text is. It is either just outputting the input or (when inside a <?php section) running PHP. It doesn't know about HTML.

Validity (in this context) only matters in the context of the generated HTML. The HTML will be valid if the PHP outputs valid content, and that will depend on what require_once 'somefile.php'; outputs.

نصائح أخرى

Of course it is. <noscript> is evaluated client side, after PHP preprocessing. So whatever you put in your somefile.php, it will be processed, and then the result sent to the client inside the <noscript> tag. However, as said by Slaks, the generated output won't be displayed until JS is disabled.

The way you include PHP in your pages has nothing to do with HTML validation, as long as the generated page is valid HTML.

Oh course you can. Noscript is designed to be used when user has disabled JavaScript, so why not? But be aware that it will always executed while rendering page. Almost all users on the Internet use JS, so it can be a little overhead.

It is valid to use PHP in the tag - PHP is evaluated on the server, and not send to the client.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top