![]() |
Web Development »
Client side scripting »
Controls
Intermediate
License: The Code Project Open License (CPOL)
Using Associative Arrays to Parse the DOM of Your WebsiteBy SerdocAn article providing JavaScript code which allows you to parse the DOM of your website easily in a cross-browser fashion |
Javascript, Dev, Design
|
|
Advanced Search |
|
|
|
This JavaScript allows a web developer to view the DOM/parse the DOM of a website that they are working on in an easy, cross-browser fashion. I wasted a lot of time trying to determine what the DOM actually looked like in different browsers in order to do complex tasks. Some books helped, some websites helped, but no one had an actual easy-to-use piece of portable JavaScript code that simply helped.
Understanding associate arrays in JavaScript is about the only possible prerequisite. See this website for information.
Getting the code to work is easy. Reference the JavaScript file in your web page and it will write itself to your page, as below:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<script language="javascript" type="text/javascript" src="includes/Jshell.js" >
</script>
<body>
<img src="images/myPageSimulation.JPG" id="TheImage" />
</body>
</html>
Once you have a script tag referencing the Jshell.js file, your web page should have a floating div appear, like so:
Let's go over how to use the control next. To move the control, click and hold your mouse over the gray bar and drag it around. Drag it to wherever you like. This allows you to still see vital data while searching the DOM. The ReOpac button toggles the opacity of the control between '.2'/''. This lets you see through the control in case it is blocking something important. The ReSize button toggles the width of the control between 230px/490px. The reason for this is if you have Jshell on a small page, like a pop up.
Let's talk about searching (we will discuss the Back, Forward and Search buttons while talking about searching). Jshell can search in a few ways. You can search via the text box below all the buttons. Simply type in what you want to search for and hit the Search button. Also, you can hit the Enter key on your keyboard while your mouse still has focus on the text box. While searching, you will notice the DOM pieces come back in multiple colors:
[0] to the end of your search string; it might get you back on track. After searching on some things, you can use the Back and Forward buttons. These buttons let you move through the last 10 searches you have performed. When Jshell first starts up, the Back button already has the following 4 searches at your disposal: document.location, navigator, window and document.
So now that you know the basics, click around and have fun! Try searching through the DOM in multiple browsers and you will see some interesting differences. You can even search on things like document.getElementById('JavaScriptSearch_Div') if you want to look at a particular object, or navigator for all your browser info.
To God, for everything. To PPK, the JavaScript masta. If you ever need to know anything about JavaScript, especially cross-browser scripting, this is the site. To Dean Edwards for the ForEach portion of my code.
The two things that really grabbed my attention while writing this code were...
.style.filter = 'alpha(opacity=20)';
.style['-moz-opacity'] = '.20';
.style.opacity = '0.2';
Having to do one thing 3 different ways for X amount of browsers is a big chunk of the cross-browser issue.
Version 1.0.0, when I wrote this article, 1/29/2008.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 1 Feb 2008 Editor: Genevieve Sovereign |
Copyright 2008 by Serdoc Everything else Copyright © CodeProject, 1999-2009 Web20 | Advertise on the Code Project |