Cleaning Useless Whitespace In Mozilla DOM
Sep 29, 2002
const notWhitespace = /S/
function cleanWhitespace(node) {
for (var x = 0; x < node.childNodes.length; x++) {
var childNode = node.childNodes[x]
if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
// that is, if it's a whitespace text node
node.removeChild(node.childNodes[x])
x--
}
if (childNode.nodeType == 1) {
// elements can have text child nodes of their own
cleanWhitespace(childNode)
}
}
}
document.addEventListener("load", function() {
cleanWhitespace(document)
}, true)
This script is intended to remove whitespace text nodes from a document. These nodes show up far more often than we want to admit, and leads to a DOM that is different in Mozilla than IE.
Make sure you use this only in documents where whitespace is expendable. XHTML documents are among these, as are MathML expressions and SVG images.
Theoretically, whitespace can be significant in some XML documents.
View 40 Replies
ADVERTISEMENT
May 12, 2007
I have a preloading page on my site for several images. When I run the code for the preloading page through the W3 validator, I get these error messages:
character "<" is the first character of a delimiter but occurred as data.
there is no attribute "name". document type does not allow element "img" here.
I tried correcting the second and third errors, but ended up messing up the whole script. If someone could fix these errors and just clean up the code in general, that would be helpful. By the way, the doctype is XHTML 1.0 strict. Code:
View 8 Replies
View Related
Sep 29, 2010
I have created the following function to expand a container depending on which one is hovered over, but need some advice on how to tidy it up.
There are four containers in all: three expand to the right and the final one expands to the left. There is a hidden element in the expandable area which appears when the container has fully expanded. For example: if I hover over .sub-main section.other, then the hidden div .other .right fades up. Mouseout and it fades down quickly as the .sub-main section.other retracts.
The working example is here: [URL]
The following code does work, but I am aware that it could probably be reduced to half as many lines using some conditional cleverness:
$(document).ready(function(){
// Hides right or left divs depending on the block
$('.other .right').hide();
$('.end .left').hide();
[Code]....
View 3 Replies
View Related
Oct 16, 2009
I have a search box. I need to remove all the special characters from the search term and then query it.-,?~!@#$%&*+-= all these characters.can anybody suggest a proper regular expression for this ? and the syntax for using it in javascript.my query is saved in var query;
View 7 Replies
View Related
Jul 16, 2009
had this in browsers areas but people told me I should put it here in Javascript because more people here would probably have seen it before and know why it happens. I have basic Javascript that rotates images. I've noticed any kind of Javascript code that rotates images has this same problem only in Mozilla. When the images rotate in Mozilla in between the rotations, Mozilla browser adds a little colored square that represents a blank image that are able to be seen does anyone know why Mozilla Browser adds that? For example when looking at this page in Mozilla can see it. if you know if this is some Mozilla problem with Javascript and images. Doesn't happen with IE and other browsers shows the images only and nothing else.
View 2 Replies
View Related
Jun 29, 2009
I have an ajax based page, which loads content from external page (html +js) So if i have a div "update_div" being updated with external content (html+js)
Let me be more specifig
Step1: Ajax content along with js loaded into update_div from a.html
Step2: Ajax content along with js loaded into update_div from b.html
What happens to the js loaded from a.html? Is it lurking in the memory or automatically/magically removed from the browser memory? I am afraid of memory leaks, if the js is still lurking in memory, the more ajax calls made, the more js is going to be held up in memory. Unless am totally wrong; i have no idea of the mechanism happening.
View 11 Replies
View Related
May 10, 2006
I'm trying to figure out reading XML into Javascript, and, frustrating as that is alone, what really boggles my mind is Mozilla's default NOT to ignore whitespace! I realize this may have its applications, but for the sake of my sanity (not to mention being cross-browser), I NEED to parse my XML document WITHOUT whitespace!
All I want to do essentially, is read in an XML document that has, let's say, 100 or so <character> nodes off the root, and output their text values into the HTML. Not so hard right? But if I make an XML document that I can actually READ (so that I don't go insane), I'm going to wind up with much more than 100 nodes thanks to reading in the whitespace... what can I do about this?
I've seen custom functions that will remove the whitespace nodes for me, but certainly there's an easier way to do this?!?
View 6 Replies
View Related
Jul 9, 2005
I'm creating a preview function that opens a new window, and then writes the values of the text fields, now my script is below, but I need to be able to make sure that the enters/breaks/carriage returns are kept when calling this page. The data I require to keep these breaks is an text area. Code:
View 3 Replies
View Related
Jul 21, 2010
How would I get this variable to allow whitespace?
var illegalChars = /W/; // allow letters, numbers, and underscores
View 11 Replies
View Related
Nov 30, 2010
I've a BIG Problem With a HUGE JS application , i'm modifying its javaScript code to work on both IE/Mozilla , currently it works fine on IE but not on Mozilla.
My main Point now is events.
Lets try with a little module, consider this function :
And it is attached in this place like :
This works fine in IE , i want to modify it to work on Mozilla.
View 2 Replies
View Related
Aug 24, 2006
I'm trying to access the source of an HTML page with as few alterations
from the actual source (as in, that seen from the View Source option)
as I can. The method document.documentElement.innerHTML returns the
HTML source, but adds HEAD and other elements if they are absent from
the source, and takes out whitespace (i.e., line feeds, carriage
returns and tabs) within tags and between tags. The follow function:
function xhr() {
xhr = new XMLHttpRequest()
xhr.open("GET","test-page.html",true);
xhr.onreadystatechange = function() {
if (xhr.readyState==4) {
alert(xhr.responseText);
}
}
xhr.send(null)
}
doesn't add or alter any tags that are absent in the source, and does
not take out line feeds within tags; it does, however, still take out
all non-line-feed whitespace within tags and all whitespace in general
between tags.
It seems that preserving whitespace is all that I need, but I haven't
found a way to do that through my searches. So is there any way to get
the unaltered HTML source of a page without innerHTML or applets, like
a better version of the XMLHttpRequest object's responseText method?
View 3 Replies
View Related
Jan 10, 2012
I am toying around with this great plugin and want to use a css class with a whitespace in it. Can I do this somehow? If I use "error message" as errorClass it wont remove the error messages. But if I use "error-messages" it works, why is that?
View 1 Replies
View Related
Dec 8, 2009
I have a string containing whitespaces, for example, "Michael Douglasemail.com". In Javascript, how can I replace the whitespace with underscore? "Michael_Douglasemail.com"
View 3 Replies
View Related
Dec 15, 2011
I print random text through php/mysql on my page and near the text there is a button which i want to be floated on the right.Between these two there is a whitespace which is not generated through php.How can i replace whitespace with "/"?I know the replace function for strings but how can i define a string here for something that doesnt exist(whitespace)?code...
View 2 Replies
View Related
Oct 12, 2005
I have a JavaScript string. I want to replace all consecutive
occurrences of whitespace characters like spaces, tabs, newlines, and
form feeds with another string.
For example, say I have a string consisting of:
-- 3 spaces
-- The characters "hello"
-- 2 newline (
) characters
-- The characters "goodbye"
-- 5 spaces
After applying some sort of regular expression to replace consecutive
occurrences of whitespace chars with the string "X", the string should
consist of the following:
-- The character "X"
-- The characters "hello"
-- The character "X"
-- The characters "goodbye"
-- The character "X"
How could I do this using regular expressions? I'm quite familiar with
JavaScript but don't know anything about regular expressions or using
them in JavaScript, so please show me step-by-step how it's done.
View 3 Replies
View Related
May 11, 2011
The following works in Chrome:
But this doesn't
The only difference is the space between 'input' and '[type=checkbox]'
Both versions work in FF and IE.
View 6 Replies
View Related
Nov 8, 2011
I currently have a <p> where it changes to a textarea when a button is clicked How do I preserve the whitespace when saving that text to a database and displaying back to a <p>?
View 2 Replies
View Related
Dec 21, 2005
How to catch whole line in the PDF document using javascript?
or How to recognize/catch whitespace signs (e.g. "
" ) in PDF document
Which method I should use?
Or any other possibility are ?
View 4 Replies
View Related
Sep 17, 2009
Major JQuery noob here. I'm working on a directory for a client's site and for some reason, in Firefox, the page is running really long with extra whitespace at the bottom where each tabbed div should end.[URL]...
View 1 Replies
View Related
Oct 5, 2001
I am having difficulty using javascript to validate form fields with whitespaces in the element names (ex: First Name, Last Name).
here's a code snippet:
###
function validate(formObj) {
if (document.form1.Payment Method.checked){
do something here...}
###
the problem is that javascript won't read the element "Payment Method" unless i mash the name into one word. (i don't want to do that because i later use the element names to provide a printable customer receipt
i tried using the ascii octal number for a whitespace in the above code (...form1.Payment40Method.checked...), but to no avail.
View 2 Replies
View Related
Dec 30, 2005
I don't like the way that a link to page top leaves the location bar with something like '#top' appended to it.
So, I'm hooking a listener to the link click event, doing a window.scroll and stopping default action. This is fine as long as the location doesn't already have a hash portion. When it does, I'd like to clean that up without causing a page reload or any server requests.
Is this possible? The closest I got with MSIE is to remove the tail end, but I can't get rid of the actual '#'.
View 6 Replies
View Related
Jul 28, 2010
I am using the jquery validation plugin to validate a form's email address field. The validation works but with the minor exception that when trailing whitespace is entered after the email the validation fails. I'm not sure if this is because of the regexp or a missing trim.
View 2 Replies
View Related
Apr 23, 2007
Using Regular Expressions (JavaScript 1.2/JScript 4+) :
String.prototype.lTrim =
function()
{
return this.replace(/^s+/,'');
}
String.prototype.lTrim =
function()
{
return this.replace(/s+$/,'');
}
String.prototype.trim =
function()
{
return this.replace(/^s+|s+$/g,'');
}
or for all versions (trims characters ASCII<32 not true
"whitespace"):
function LTrim(str) {
for (var k=0; k<str.length && str.charAt(k)<=" " ; k++) ;
return str.substring(k,str.length);
}
function RTrim(str) {
for (var j=str.length-1; j>=0 && str.charAt(j)<=" " ; j--) ;
return str.substring(0,j+1);
}
function Trim(str) {
return LTrim(RTrim(str));
}
http://msdn.microsoft.com/library/d...363906a7353.asp
http://docs.sun.com/source/816-6408-10/regexp.htm
View 27 Replies
View Related
Oct 29, 2006
I have an 'input' that is of type= "image", and name="butt",
that I need to enable/disable from time to time.
In IE (6) I used [document.theform..butt.disabled=condition] and it worked
fine. However, in a Mozilla (latest vers, no number avail) it doesn't see
this as an object. As a workaround I declared a global var 'theButton' and
used 'onLoad="theButton=this;"' within that 'input' to set the value, and
this works fine in both Moz & IE.
Having to use a global var is not a problem, but I would like to know why
the original attempt didn't work in both browsers? The 'form' that 'butt'
is a member of contains 1 select, 3 type="text" inputs, and finaly the
type="image" input.
Perhaps Moz doesn't add an 'input' of type="image" to the collection if the
types are mixed?
View 4 Replies
View Related
Jul 20, 2005
I have this script and I want to adapt it to the DOM of most / all well
known browsers like mozilla and netscape.. at the moment it only works in
ie4+ en ns6. can anybody give me some hints?
This is used for making a tree <li><ul>
var ns6 = document.getElementById && !document.all;
var ie4 = document.all && navigator.userAgent.indexOf("Opera") == -1;
function checkcontained(e)
{
var iscontained = 0;
cur = ns6 ? e.target : event.srcElement;
if (cur.id == "foldheader")
{
iscontained = 1;
}
else
{
while (ns6 && cur.parentNode || (ie4 && cur.parentElement))
{
if (cur.id == "foldheader" || cur.id == "foldinglist")
{
iscontained = (cur.id == "foldheader") ? 1 : 0;
break;
}
cur = ns6 ? cur.parentNode : cur.parentElement;
}
}
if (iscontained)
{
var foldercontent = ns6 ? cur.nextSibling.nextSibling :
cur.all.tags("UL")[0];
if (foldercontent.style.display == "none")
{
foldercontent.style.display = "";
cur.style.listStyleImage = "url(images/open.gif)";
}
else
{
foldercontent.style.display = "none";
cur.style.listStyleImage = "url(images/fold.gif)";
}
}
}
if (ie4 || ns6)
{
document.onclick = checkcontained;
}
View 6 Replies
View Related
Jul 23, 2005
I have some functions in a script in which I'm manipulating the
innerText and background colors of certain rows in a table. The lines
below work OK in IE but when I try them in Mozilla, I get an error
that says: "document.getElementById('TableX').rows is not a
function".
thisRow = document.getElementById('TableX').rows(1);
thisRow.style.background = 'white'
Can anyone give me a clue as to how to fix this so that it will work
in both browsers?
View 2 Replies
View Related