How to access HTML headers?

J

Jeremy J Starcher

I am developing a script under GreaseMonkey and IE7Pro for a social
website I am involved with.

When accessing some pages (user profiles) a 404 error is returned if the
profile does not exist.

Fx returns the page to me as given by the server.

IE7 "helpfully" transforms the simple body contents of "404-Bad Request"
to something far more elaborate, thus keeping from doing a simple
contents check.

I'm looking for a reliable way to detect these 404's. Anyone have advice?
 
T

Thomas 'PointedEars' Lahn

Jeremy said:
I am developing a script under GreaseMonkey and IE7Pro for a social
website I am involved with.

When accessing some pages (user profiles) a 404 error is returned if the
profile does not exist.
[...]
I'm looking for a reliable way to detect these 404's. Anyone have advice?

IXMLHTTPRequest::status


PointedEars
 
J

Jeremy J Starcher

Jeremy said:
I am developing a script under GreaseMonkey and IE7Pro for a social
website I am involved with.

When accessing some pages (user profiles) a 404 error is returned if
the profile does not exist.
[...]
I'm looking for a reliable way to detect these 404's. Anyone have
advice?

IXMLHTTPRequest::status


PointedEars

Seems that would do it, but I can't seem to access it from with GM or
IE7Pro (unless I missed something in my searching.)

GreaseMonkey runs in a weird space, somewhere below chrome level, yet
above the page level. It doesn't have access to much more than
Javascript has, so if there was a standard(ish) Javascript/DOM method,
that is what I'd need.

(If document.status existed, that would be the cat's meow, I think.)
 
T

Thomas 'PointedEars' Lahn

Jeremy said:
Jeremy said:
I am developing a script under GreaseMonkey and IE7Pro for a social
website I am involved with.

When accessing some pages (user profiles) a 404 error is returned if
the profile does not exist.
[...]
I'm looking for a reliable way to detect these 404's. Anyone have
advice?
IXMLHTTPRequest::status
[...]

Seems that would do it, but I can't seem to access it from with GM or
IE7Pro (unless I missed something in my searching.)

Well, since I had never done anything with Greasemonkey, I went to the
Wikipedia article which lead me to GM's homepage where it says:

| Thursday, June 12, 2008
| Greasemonkey Version 0.8
|
| [...]
| Also:
|
| * GM_xmlhttpRequest now includes the finalUrl property.

And then the "Learn to write scripts" quite naturally led to:

<http://diveintogreasemonkey.org/api/gm_xmlhttprequest.html>

where it says:

| GM_xmlhttpRequest — make an arbitrary HTTP request

So that looks like a good starting point.
GreaseMonkey runs in a weird space, somewhere below chrome level, yet
above the page level. It doesn't have access to much more than
Javascript has, so if there was a standard(ish) Javascript/DOM method,
that is what I'd need.

That is probably why GM provides this object. The GM extension itself runs
on the chrome level where it can use all kinds of XPCOM Components without
constraints, including nsIJSXMLHttpRequest.

I do not know about IE7Pro, though. (What is it anyway?)


PointedEars
 
J

Jeremy J Starcher

Jeremy said:
Jeremy J Starcher wrote:
I am developing a script under GreaseMonkey and IE7Pro for a social
website I am involved with.

When accessing some pages (user profiles) a 404 error is returned if
the profile does not exist.
[...]
I'm looking for a reliable way to detect these 404's. Anyone have
advice?
IXMLHTTPRequest::status
[...]

Seems that would do it, but I can't seem to access it from with GM or
IE7Pro (unless I missed something in my searching.)

Well, since I had never done anything with Greasemonkey, I went to the
Wikipedia article which lead me to GM's homepage where it says:

| Thursday, June 12, 2008
| Greasemonkey Version 0.8
|
| [...]
| Also:
|
| * GM_xmlhttpRequest now includes the finalUrl property.

And then the "Learn to write scripts" quite naturally led to:

<http://diveintogreasemonkey.org/api/gm_xmlhttprequest.html>

where it says:

| GM_xmlhttpRequest — make an arbitrary HTTP request

So that looks like a good starting point.

*nods* I can do it that way, but it is hackish since it involves
reloading the current page via GM_xmlhttpRequest.

I was hoping to find a plain-old-regular Javascript-like-you-would-
normaly-use-way to do it.

There might not be one.

That is probably why GM provides this object. The GM extension itself
runs on the chrome level where it can use all kinds of XPCOM Components
without constraints, including nsIJSXMLHttpRequest.

I do not know about IE7Pro, though. (What is it anyway?)

IE7Pro < http://www.ie7pro.com/ > is billed as the "ultimate" extension
for IE6 and 7 on XP+. Adds user scripts, crash recovery, Mouse Gesture,
save page as image and a bunch of others.

There is a shim script that makes IE7Pro work with many GM scripts.
 
T

Thomas 'PointedEars' Lahn

Jeremy said:
[<http://www.greasespot.net/>]
And then the "Learn to write scripts" quite naturally led to:

<http://diveintogreasemonkey.org/api/gm_xmlhttprequest.html>

where it says:

| GM_xmlhttpRequest — make an arbitrary HTTP request

So that looks like a good starting point.

*nods* I can do it that way, but it is hackish since it involves
reloading the current page via GM_xmlhttpRequest.

I was hoping to find a plain-old-regular Javascript-like-you-would-
normaly-use-way to do it.

There might not be one.

Curious. Why can't you make a HEAD request using the URI of the user
profile document resource, and navigate there only if that request is
successful?

ACK, thanks.


PointedEars

P.S.
Please trim your quotes to the necessary minimum to retain context and stop
quoting signatures.
 
J

Jeremy J Starcher

Curious. Why can't you make a HEAD request using the URI of the user
profile document resource, and navigate there only if that request is
successful?

Ah! There is an idea that didn't cross my mind. I've never done just a
HEAD request, but if it works, that will be a better route to take.
Thanks.

I'll run some tests tonight.
P.S.
Please trim your quotes to the necessary minimum to retain context and
stop quoting signatures.

ACK. I'll kick myself in the seat of my pants to remind me.
 
M

Michael Wojcik

You've already received what looks like good advice from Thomas (XHR a
HEAD request and check the status) for this problem, but I wanted to
make a quick comment on your subject line. The information you're
looking for is neither a header nor anything to do with HTML; it's the
HTTP Status-Code. (See RFC 2616.)

I mention this only because the wrong nomenclature could be confusing
for maintainers.
 
J

Jeremy J Starcher

You've already received what looks like good advice from Thomas (XHR a
HEAD request and check the status) for this problem, but I wanted to
make a quick comment on your subject line. The information you're
looking for is neither a header nor anything to do with HTML; it's the
HTTP Status-Code. (See RFC 2616.)

Correction accepted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,356
Latest member
Tommyhotly

Latest Threads

Top