简体   繁体   中英

Why are the html-tags inside <noscript> shown as text

I have a noscript part:

<noscript>
  <h1><?php echo $php_title; ?></h1>
  <div><?php echo $php_abstract; ?></div>
</noscript>

When I try this in a .html file (with the php tags removed, of course) it works as expected, but when in a .php file I get this visible output in the browser (ie the is not treated as an html tag):

<h1>Stephen Porges "The Polyvagal Theory"</h1>

I do not set any special headers with PHP:

<?php
ini_set('display_errors', 1); 
error_reporting(E_ALL);

require_once 'HTTP/Request2.php';

$url = "https://api.zotero.org/groups/56508/items/3B6TR25A?format=atom&content=json";
$r = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);

$r->setConfig(array(
    'ssl_verify_peer'   => FALSE,
    'ssl_verify_host'   => FALSE
));
try {
    $response = $r->send();
    if ($response->getStatus() == 200) {
            $body = $response->getBody();
            $xml = new SimpleXMLElement($body);
            $php_content = $xml->content;
            $php_json = json_decode($php_content);
            $php_title = $php_json->title;
            $php_abstract = $php_json->abstractNote;
    }
} catch (HttpException $ex) {
    echo $ex;
    exit;
}

?>
<!DOCTYPE html>
<html lang="en">

The document is returned as text/html according to the browser.

I use Chrome and there is maybe a bug here, but it seems strange that it works ok in .html but not .php if that is the reason.

Any idea of what is going on here?

This is an issue with chrome where it is not rendered the first time the browser loads the page with JavaScript disabled. If you refresh the page after it shows plain text, it should be rendered properly.

This issue has already been reported:

https://code.google.com/p/chromium/issues/detail?id=235158

One person from that website suggested a workaround of using something like:

<div id="noscript">What was in the noscript-tag ..... </div>
<script type="text/javascript">
     document.getElementById('noscript').style.display="none";
     // rest of script
</script>

Therefore, it would only hide the elements if JavaScript is enabled.

I wouldn't say that it is that big of a deal. For example, Stack Overflow uses <noscript> tags regardless and the same occurs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM