Document Object Model and "Show Pictures"

G

Greg Lovern

Using the Document Object Model, how do I turn off "Show Pictures"?

I'm using the DOM to navigate to thousands of small pages, in a loop.
Each of them has a picture which I don't care about. If I turn off
"Show Pictures" in the browser's options, it goes much faster.

That's fine for my own computer, but I can't expect others using this
code to do that. How can I use the DOM to toggle "Show Pictures" off
and back on?


Thanks,


Greg
 
T

Thomas 'PointedEars' Lahn

Greg said:
Using the Document Object Model, how do I turn off "Show Pictures"?

I'm using the DOM to navigate to thousands of small pages, in a loop.
Each of them has a picture which I don't care about. If I turn off
"Show Pictures" in the browser's options, it goes much faster.

That's fine for my own computer, but I can't expect others using this
code to do that. How can I use the DOM to toggle "Show Pictures" off
and back on?

I don't think you can with a standard browser security setting. However,
you can probably add a stylesheet that provides a CSS declaration to hide
(display: none !important) all `img' (or `object') elements in that context
(even without any scripting). As `display: none' means the element should
be rendered as if it was not parsed, it is possible that no image data will
be requested.


PointedEars
 
M

Martin Honnen

Greg said:
Using the Document Object Model, how do I turn off "Show Pictures"?

I'm using the DOM to navigate to thousands of small pages, in a loop.
Each of them has a picture which I don't care about. If I turn off
"Show Pictures" in the browser's options, it goes much faster.

That's fine for my own computer, but I can't expect others using this
code to do that. How can I use the DOM to toggle "Show Pictures" off
and back on?

Dynamically adding a CSS rule

var style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(
'img { display: none !important; }'));

document.documentElement.getElementsByTagName('head')[0].appendChild(style);

should hide pictures, at least in browsers like Mozilla or Opera. I
think IE does not like appendChild on style or script elements but has a
proprietary way of adding a stylesheet or at least a rules to a stylesheet.

Once you have added the stylesheet with the single rule at the end of
the head you can disable and enable it e.g.
style.disabled = true;
will disable the stylesheet.
 
G

Greg Lovern

I don't think you can with a standard browser security setting.  However,
you can probably add a stylesheet that provides a CSS declaration to hide
(display: none !important) all `img' (or `object') elements in that context
(even without any scripting).  As `display: none' means the element should
be rendered as if it was not parsed, it is possible that no image data will
be requested.


Thanks, but I should have mentioned that I have no control over the
content of the web pages. This is basically a scraping project, though
one that is approved by the owner of the pages.


It looks like I should be able to do it by toggling this registry key
value, before creating the DOM object:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Display
Inline Images (yes/no)


Any thoughts? I won't have time to try it until probably Monday. It
does what I want if I edit the registry manually, but I don't know if
I'm going to run into security issues doing it programmatically.


Thanks,

Greg
 
T

Thomas 'PointedEars' Lahn

Greg said:
Thanks, but I should have mentioned that I have no control over the
content of the web pages. This is basically a scraping project, though
one that is approved by the owner of the pages.

Except if the "web pages" are displayed in (i)frames, you do not need
control over their content as your stylesheet would be applied, and a
context-sensitive CSS selector would allow you to differentiate between your
content and their content.
It looks like I should be able to do it by toggling this registry key
value, before creating the DOM object:

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Display
Inline Images (yes/no)


Any thoughts?

This only works with Internet Explorer on Microsoft Windows,
if at all (at least a refresh is required in that environment).
I won't have time to try it until probably Monday. It
does what I want if I edit the registry manually, but I don't know if
I'm going to run into security issues doing it programmatically.

Yes, you will run into security issues. ISTM you have not thought this
through: If every Web author was allowed to manipulate the Windows Registry
of their visitors with a standard security setting, that would result in a
pretty bad Web experience for currently about 90% of Web users.

Please trim your quotes, and observe what is on-topic in this newsgroup and
what is not. <http://jibbering.com/faq/#posting>


PointedEars
 
G

Greg Lovern

Yes, you will run into security issues.  ISTM you have not thought this
through: If every Web author was allowed to manipulate the Windows Registry
of their visitors with a standard security setting, that would result in a
pretty bad Web experience for currently about 90% of Web users.

This is not a web application in that sense. It works with html pages
it gets from the web, but it doesn't run from a web page.

Editing the registry programmatically is generally not rocket science,
but I've run into cases where editing a certain key etc. requires
higher security.

observe what is on-topic in this newsgroup and
what is not.

I believe I have.


Greg
 
T

Thomas 'PointedEars' Lahn

Greg said:
This is not a web application in that sense. It works with html pages
it gets from the web, but it doesn't run from a web page.

Editing the registry programmatically is generally not rocket science,
but I've run into cases where editing a certain key etc. requires
higher security.

Yes, several non-HKCU keys would be restricted to Administrator access.
However, although strongly recommended against, I had to observe that many
Windows users, encouraged by a stupid setup default and system design that
often requires it for non-Admin tasks, are even online with Administrator
privileges. ISTM Vista has tried to solve the problem, but only partially
succeeded (people are just blindly confirming the "Go Admin" dialog now).
I believe I have.

(Editing) the Windows Registry (programmatically to change a setting in
Internet Explorer) is hardly on-topic here. However, as a final piece of
advice, you will need an API with ECMAScript binding to do it with MS
JScript there. MSHTML provides ActiveX/COM. In any event, users will not
be pleased that your application manipulates their Registry setting. What
if your application crashes, which happens frequently on Windows, while
doing that?


F'up2 poster since I don't know where this could be on-topic. Change into
an appropriate newsgroup as you see fit.

PointedEars
 
G

Greg Lovern

In any event, users will not
be pleased that your application manipulates their Registry setting.  

Most setup programs do exactly that. The widely used Regsvr32.dll does
it too. Many applications store settings in the registry and edit them
as the user interacts with the program. A user who doesn't want their
registry edited should probably never do much of anything.

What
if your application crashes, which happens frequently on Windows, while
doing that?

The same thing that would happen if IE crashed when changing the
registry setting I mentioned as a result of the user interactively
changing that option (Show Pictures) in IE.

It isn't my fault that Windows has that issue. Of course I use the
standard Windows APIs to do the registry edits. If that displeases a
user, I don't know what would please them.

F'up2 poster since I don't know where this could be on-topic.  Change into
an appropriate newsgroup as you see fit.

The original question was on topic. I apologize that the followup
question was not, but you are overreacting. Get your panties out of
your crack.

Greg
 
T

Thomas 'PointedEars' Lahn

Greg said:
Most setup programs do exactly that.

They do it upon setup and uninstall, and they add/modify keys in their
namespace and the Uninstall subtree. I for one have yet to see a widely
distributed application that modifies IE settings. AFAIK not even MSD
does that even though it integrates with IE.
The widely used Regsvr32.dll does it too.

Apples, oranges.
Many applications store settings in the registry and edit them as the
user interacts with the program.

*Their* settings.
A user who doesn't want their registry edited should probably never do
much of anything.

Non sequitur.
The same thing that would happen if IE crashed when changing the registry
setting I mentioned as a result of the user interactively changing that
option (Show Pictures) in IE.

Yes, so you should keep your hands off the IE part of the Registry.
It isn't my fault that Windows has that issue. Of course I use the
standard Windows APIs to do the registry edits. If that displeases a
user, I don't know what would please them.

You miss the point. If your application crashes, the user will find that
their browser no longer displays images without necessarily knowing what to
do about it. That would be your fault.
The original question was on topic. I apologize that the followup
question was not, but you are overreacting. Get your panties out of your
crack.

Score adjusted

PointedEars, F'up2 poster
 
G

Greg Lovern

They do it upon setup and uninstall, and they add/modify keys in their
namespace and the Uninstall subtree. I for one have yet to see a widely
distributed application that modifies IE settings. AFAIK not even MSD
does that even though it integrates with IE.

I don't know if thousands of users worldwide in the last 6 years
counts as "widely distributed", and I don't know if you would consider
the issue to apply equally to Excel as to IE, but my Excel add-ins'
setup programs modify Excel's registry settings to make Excel load
them as add-ins. The only complaints have been on the rare occasions
when the changes didn't get written (higher than normal security,
probably) and the user had to manually tell Excel to load them as add-
ins.

You miss the point. If your application crashes, the user will find that
their browser no longer displays images without necessarily knowing what to
do about it. That would be your fault.

I'll give the user a dialog that briefly explains the issue and has
buttons to turn the registry setting on/off, and buttons to continue
or cancel. That way:
-- It's under the user's control, and
-- If the problem does happen, the user can just come back in, click
the button to turn the setting back on, and click cancel.

Score adjusted

Mmm, do that again. Felt good. You must have a lot of experience doing
that.


Greg
 
G

Greg Lovern

What does that mean?

At first I wasn't sure. I tried googling "Score adjusted", but most of
the hits were of newsgroup posts by "PointedEars". Same thing happened
when I tried googling "F'up2" and "F'up2 poster".

Then I realized he was probably talking about the "rate this post"
thing in Google newsgroups, or something similar for wherever he reads
newsgroups.


Greg
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top