[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2013-06-19
5
Medium Priority
?
789 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 44

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 44

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 44

Accepted Solution

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

650 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