Solved

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

Posted on 2013-06-19
5
719 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 42

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 42

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 42

Accepted Solution

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
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.

760 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

19 Experts available now in Live!

Get 1:1 Help Now