Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

php

noscript

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 (i.e. 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?

like image 871
Leo Avatar asked May 28 '14 23:05

Leo


People also ask

What does noscript tag do in HTML?

<noscript>: The Noscript element The <noscript> HTML element defines a section of HTML to be inserted if a script type on the page is unsupported or if scripting is currently turned off in the browser. Content categories. Metadata content, flow content, phrasing content.

Where do you put noscript in HTML?

In HTML5 the <noscript> tag can be placed in the <head> and <body> elements.

What happens if you specify a noscript element within a webpage?

The <noscript> tag defines an alternate content to be displayed to users that have disabled scripts in their browser or have a browser that doesn't support script.

What is script and noscript in HTML?

The <noscript> tag in HTML is used to display the text for those browsers which does not support script tag or the browsers disable the script by the user. This tag is used in both <head> and <body> tag. Note: This tag is used in those browsers only which does not support scripts. Syntax: <noscript> Contents... </


1 Answers

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.

like image 175
Anonymous Avatar answered Nov 14 '22 02:11

Anonymous