Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Hiding HTML from the curious - YUI


  • Please log in to reply
No replies to this topic

#1 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:05:29 PM

Posted 01 October 2009 - 03:11 AM

That is sort of a misleading title, because in all reality, there is no way that one can hide HTML once it has been rendered in the browser, no matter the claims. I hate to even link to their site, but I think people should be aware of scams. This is a prime example. Let me say this again. Once a web page has been rendered in my browser, I can view the source code simply using a plug-in like Firebug.

Personally, I think it is a waste of time to try and hide source code. A loop is a loop, a variable is a variable, etc. I understand that it might be advantageous to hide some of the business logic, but really, how often does one write code that has not already been written before? I can only think of a couple times that I have written code that I haven’t begged, borrowed, or stolen from somewhere. And even when I did, it hasn’t been anything so earth-shattering that I needed to hide it. And really, when it comes to web pages, there are only so many ways to skin a cat. For you PETA folks, just relax. It is only an expression.

At any rate, I have discovered that there are some ways of hiding your HTML from the casual user. Of course, even a moderately sophisticated user can still retrieve the source. The reason that I discovered this is because one of the projects I am working on requires that the view be dynamically generated. And it turns out that the YUI library is perfectly suited for this. Anyway, I thought simple example of some of what I have been working on was in order.

Getting Started
The first thing one needs are the proper imports. In this example I’ll also be using one of the Event imports also. We will start out with the following code and build our page step by step, testing along the way. Just as a note, we will be using Javascript closures to encapsulate our Javascript functions. The use of closures is beyond the scope of this tutorial, so for those that are not familiar with the syntax, it may look a little strange. The first thing we want to do is make sure that our Javascript is properly encapsulated:

<!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>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
   &lt;script src="http://yui.yahooapis.com/combo?2.8.0r4/build/yahoo-dom-event/yahoo-dom-event.js&2.8.0r4/build/element/element-min.js" type="text/javascript"></script>
   &lt;script type="text/javascript">
	 
	(function () {
	   YAHOO.util.Event.onDOMReady(alert("hello"));
   }());
	
	
  </script>
   </head>
	
   <body>
	
   <div id="myDiv">
   </div>
	
   </body>
	
   </html>

When we run this code, we will get an alert displaying our “hello” message. If you do not, verify that you have Javascript enabled, and that you do not have syntax errors. So now the next step is to just add some simple content. You should have noticed that we have a div with the id of ‘myDiv’. That is going to contain our content. so the first thing we need to do is to create a pointer to that div. I will show the completed code at the end of this post, but for now here is the line of code that we need to create a pointer to our div: var container = new YAHOO.util.Element("myDiv");

Now that we have the pointer to our div, we can add some content. Keeping it simple for now, we will just add a span with “Hello World” as the content. I know, the whole “Hello World” thing has been done to death, but so has “foo”. We need a few more lines of java script:


Rest of the lesson is here.

BC AdBot (Login to Remove)

 





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users