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
Solved

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

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

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 …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
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…

860 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