简体   繁体   中英

Delphi TChromium : how to toggle between show and hide images with Options.ImageLoading

I'm using TChromium to navigate to pages. It has the property Options.ImageLoading , where you can specify if you want to show website's images or not.

Problem is it works only with the option is set in design time. If i change this property in runtime, it has no effect. Here is an example code ; what i wanted to achieve in this example was open test1.com showing images and open test2.com hiding images. Unfortunately both sites are loaded with images, ignoring the option i set.

Any ideas how to fix this ? I want to be able to show images only for certain websites.

procedure tform1.button1click(Sender : TObject);
begin
chromium1.options.ImageLoading = STATE_ENABLED;
chromium1.load('www.test1.com');
end;

procedure tform1.button2click(Sender: TObject);
begin
chromium1.options.ImageLoading = STATE_DISABLED;
chromium1.load('www.test2.com');
end;

Because @delphirules actually ask about deffered image loading, and next answer is greatest (and applicable to any chromium-based solution) i'm re-post part of this answer here:

You can load a webpage with webkit.webprefs.loads_images_automatically preference set to false then later change it to true and the images will load (you cannot unload images once they're loaded).

Thanks to user amaitland for great findings. :)

Try this:

  • Create two instances of TChromium, one with options.ImageLoading := STATE_ENABLED and the other with options.ImageLoading := STATE_DISABLED

  • Then, when you want a page to be loaded, make the first one visible and the other one not visible and vice versa.

Obviously, there may be a bit more to do than that, but at least it would avoid having to recreate the browser each time you want to change.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM