Solved

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

Posted on 2013-06-19
5
749 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

688 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