474,046 Members | 4,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keeping whitespace in responseText, etc.

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.docume ntElement.inner HTML 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.onreadystat echange = function() {
if (xhr.readyState ==4) {
alert(xhr.respo nseText);
}
}
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?

Thanks,
Eric

Aug 24 '06 #1
3 3573


e271828 wrote:

alert(xhr.respo nseText);
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.
responseText gives you the text as the browser decodes it from the HTTP
response body. There might be issues with responseText with properly
decoding characters depending on the encoding of the response but I
don't think that the white space stripping occurs that you claim above.

I suspect rather that you use Mozilla respectively Firefox and that the
white space issue you notice is simply the somehow broken alert dialog
in Mozilla where lots of white space is collapsed and not rendered.
For example if you do e.g.
alert(['Line 1', ' Line 2', 'Line 3'].join('\r\n'))
with Mozilla then the alert dialog will not show the white space at the
beginning of Line 2 at all.

Is that Mozilla you are using? Then I think the issue you see is simply
alerting the responseText and not white space missing in responseText.

Or which browser do you have where you think that white space gets lost
when using responseText?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 24 '06 #2
You were right, more or less. Unlike innerHTML, responseText doesn't
alter the HTML it gets; but when shown in an alert box it can seem like
responseText mangles whitespace . When you try
responseText.sp lit("\t") or .split("\n") in a for loop for as many
results those methods return, however, you will see that the number of
the last alert plus 1 equals however many tabs or new lines you have in
your actual source (unlike innerHTML).
--
But now I've encountered another problem I haven't been able to find an
answer to: how do I get external URL's (say, http://www.google.com) to
open in the XMLHttpRequest, instead of just local files?
Martin Honnen wrote:
e271828 wrote:

alert(xhr.respo nseText);

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.

responseText gives you the text as the browser decodes it from the HTTP
response body. There might be issues with responseText with properly
decoding characters depending on the encoding of the response but I
don't think that the white space stripping occurs that you claim above.

I suspect rather that you use Mozilla respectively Firefox and that the
white space issue you notice is simply the somehow broken alert dialog
in Mozilla where lots of white space is collapsed and not rendered.
For example if you do e.g.
alert(['Line 1', ' Line 2', 'Line 3'].join('\r\n'))
with Mozilla then the alert dialog will not show the white space at the
beginning of Line 2 at all.

Is that Mozilla you are using? Then I think the issue you see is simply
alerting the responseText and not white space missing in responseText.

Or which browser do you have where you think that white space gets lost
when using responseText?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 24 '06 #3


e271828 wrote:

But now I've encountered another problem I haven't been able to find an
answer to: how do I get external URL's (say, http://www.google.com) to
open in the XMLHttpRequest, instead of just local files?
Inside the normal browser context the same origin policy applies for
request XMLHttpRequest makes thus you can only successfully make
requests back to the server your document with the script comes from.
So with client-side script you would need to have your own server side
script function as a proxy to fetch URLs from e.g. www.google.com.

Outside of the browser sandbox (e.g. on Windows in a HTA (HTML
application) or with a Windows Script Host script or an ASP page or with
the Mozilla browser if you write an extension) those restrictions do not
apply.

IE also has a zone model with different security zones which can be
configured separatedly where for the trusted zone for instance you could
change the settings to allow the request to other domains.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2696
by: Robert Oschler | last post by:
Hello, Given the following program: -------------- import re x = "The dog ran. The cat eats! The bird flies? Done." l = re.split("", x)
9
5610
by: fochie | last post by:
Greetings, I'm having a problem when I try to GET a file from my server via xmlhttp when using Mozilla. With IE I can get any type of file fine, get/display headers fine, etc. With Mozilla, using the same HTML/JS it always returns no data (xmlhttp.responseText is null). When I try to get headers using Mozilla or display the http status code I get some obscure exception in the javascript console that I've given up on searching for an...
6
7834
by: mihirnmehta | last post by:
This is my code function getDetails() { var name = document.getElementById("movie_name").value; if (window.XMLHttpRequest) //For Mozilla Browsers { XMLHttp=new XMLHttpRequest() }
1
4346
by: KAS | last post by:
First of all, I am very much a newbie... From what I have read, it seems to me that both of these should be filled in all the time. The responseXML being a DOM representation and the responseText being a string representation of the response. Right? If so, then why do I sometimes have a responseText with no responseXML? A second part to that question is accessing the data in responseText. Here is what I have done. On the server side,...
4
5127
by: -Lost | last post by:
For example: var newlines = 'a\n\nb\n\nc'; alert(newlines); Yet, if I get that *exact* same line from an XMLHttpRequest's responseText, it is always alerted as: a\n\nb\n\nc
1
9063
by: farghal | last post by:
Hello as many people I'm new to ajax but trying my best to understand. At this point I got a problem I'm not able to solve. I've looked on several forums and googled internet but I can't find a solution :S. This is the basic idea: I'm trying to implement Ajax in a Portal page created in weblogic 9.2. I've created a portlet with the name Ajax.jsp and an additional page called test.jsp. Ajax.jsp is the main portlet page. And uses the...
6
3158
by: lazukars | last post by:
Hi, I am attempting an ajax request. I am using PHP serverside. Below is what the response text should be. ajaxRequest.responseText ="{username_is_taken : "This username has been taken",}" However, the only way I can get the responseText to work on a website via an alert is to take out the comma before the curly bracket. By taking out I mean just not printing the comma with the rest of the string in PHP. If I take out this comma...
5
6658
by: wendallsan | last post by:
Hi all, I'm running into a situation where it seems that JS stops executing as soon as I call an eval in my script. I have an Ajax.Request call to a PHP page that builds a JS object and returns it as the responseText. I want to attach that object to the document (or anywhere else that would allow me to access it later), and to do that, I THINK I need to eval it because it's just a string otherwise. My problem is as soon as I execute a...
4
2550
RamananKalirajan
by: RamananKalirajan | last post by:
Hi All, I am using Ajax inorder to retrieve a data from the db which is an xml and i am parsing the responseText into an xml. the code what i had tried is working well with IE, but the same makes a lot of trouble in mozilla any help would be greatful the following is the code if (httpRequest.readyState == 4) { if(httpRequest.status == 200) { var pricingSummaryXML = httpRequest.responseText;
0
10339
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11604
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11143
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6654
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6837
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5420
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3974
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.