Solved

jQuery: Firefox and Chrome Render Content Inside <noscript> Differently

Posted on 2013-06-19
5
727 Views
Last Modified: 2013-07-08
Firefox renders this the way I want it to but Google Chrome uses entity encoding.  How can the code be modified to work correctly in Google Chrome?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
 var homeData = $('noscript#homePage').html();
 $('body').html(homeData);
 alert(homeData);
});

</script>

</head>
<body>

<noscript id="homePage">
<h1>Hello World</h1>
</noscript>

</body>
</html>

Open in new window

0
Comment
Question by:hankknight
  • 3
  • 2
5 Comments
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39259004
Read the value in as text() and then set it out as html():

$(document).ready(function() {
     var homeData = $('noscript#homePage').text();
     $('body').html(homeData);
     alert(homeData);
});

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
ID: 39259217
That gets rid of the HTML tags altogether!  I want all the HTML code, not just the text.
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39259381
The text() method works OK for me, but your problem/issue does seem to be a bug/feature within Chrome - effectively the <noscript> tag only becomes fully available if you have javascript disabled - that's exactly what it's designed for!

It's not really clear from your code what you are trying to achieve - it seems that when JS is enabled you are trying to read the content designed specifically for when JS is disabled!! Can't for the life of me figure out why you would ever need to do this. It makes no sense! It seems that you are trying to show certain content whether JS is enabled or disabled so why not just show it normally??

Here's a few pages that may help explain things a bit more:

http://stackoverflow.com/questions/828195/why-does-retreiving-html-from-inside-a-noscript-return-htmlentities

http://stackoverflow.com/questions/620896/access-contents-of-noscript-with-javascript

http://stackoverflow.com/questions/4576131/jquery-how-can-i-get-the-html-from-inside-noscript-to-display-in-a-differend-di
0
 
LVL 16

Author Comment

by:hankknight
ID: 39269464
This works for me:
 var homeData = $('<textarea/>').html($('noscript#homePage').html()).val();

Open in new window

0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39269665
Still don't see the point of this!!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now