schwobeseggl.de

ein Neigschmecktr in Baden

  • Artikel
  • Fotos
  • Impressum

DOM: Javascript vs. C++

Posted at April 22, 2009

Musste das Syntax-Highlighting wegmachen, das hat das Layout zerstört

Ich geh gerade mal sterben. Beide Funktionen haben dieselbe Funktionalität, nämlich alles Bilder innerhalb einer Webseite zu “verstecken”. Hier der Javascript-Code

function RemoveImages(doc) {
  var images = doc.images;
    if (images != null) {
      for (var i = 0; i < images.length; i++) {
        var img = images.item(i);
        img.style.display = "none";
      }
    }
}


Hurra. Nun in C++

void CHelloWorldBHO::RemoveImages(IHTMLDocument2* pDocument) {
  CComPtr<IHTMLElementCollection> spImages;

  // Get the collection of images from the DOM.
  HRESULT hr = pDocument->get_images(&spImages;);
  if (hr == S_OK && spImages != NULL) {
    // Get the number of images in the collection.
    long cImages = 0;
    hr = spImages->get_length(&cImages);
    if (hr == S_OK && cImages > 0) {
      for (int i = 0; i < cImages; i++) {
        CComVariant svarItemIndex(i);
        CComVariant svarEmpty;
        CComPtr<IDispatch> spdispImage;

        // Get the image out of the collection by index.
        hr = spImages->item(svarItemIndex, svarEmpty, &spdispImage);
        if (hr == S_OK && spdispImage != NULL) {
          // First, query for the generic HTML element interface...
          CComQIPtr<IHTMLElement> spElement = spdispImage;

          if (spElement) {
            // ...then ask for the style interface.
            CComPtr<IHTMLStyle> spStyle;
            hr = spElement->get_style(&spStyle;);

            // Set display="none" to hide the image.
            if (hr == S_OK && spStyle != NULL) {
              static const CComBSTR sbstrNone(L"none");
              spStyle->put_display(sbstrNone);
            }
          }
        }
      }
    }
  }
}

Kommentar:

Interacting with the DOM in C++ is more verbose than JavaScript, but the code flow is essentially the same.

Quelle: http://msdn.microsoft.com/en-us/library/bb250489.aspx

Ähnliche Artikel:

  1. Registry Pattern in Javascript
  2. Vererbung in Javascript anhand von Exceptions
  3. Wie Weihnachten
  4. Java Collection Interface
  5. Javascript-Objekte

PC & Accessoires, Sonstiges
  • Digg
  • Stumbleupon
  • Del.icio.us
  • Reddit
  • Technorati

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

2 Responses to “DOM: Javascript vs. C++”
  • joschi says:
    22. April 2009 at 13:39

    Jaja, immer die Verhältnismäßigkeit beachten. Versuch mal ein Betriebssystem mit JavaScript zu programmieren. ;)

    Mit einem Hammer sägt es sich eben schlecht.

  • pennywise says:
    22. April 2009 at 14:26

    guckst du hier

    Ok, ist kein OS … ich weiß ja was du meinst :)

Search

Archives

  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • March 2007
  • March 2006
  • November 2005
  • October 2005
  • September 2005

Categories

  • Arbeit
  • PC & Accessoires
    • Linux
  • Pfadfinder
  • Programmiersprachen
    • C#
    • Java
    • PHP
  • Sonstiges
  • Spass
  • Studium
    • Diplomarbeit
    • Praxissemester
    • USA
  • Uncategorized
  • Wordpress
  • Recent Posts

    • URLdump
    • Flagge zeigen
    • London
    • $N zufällig gewählte Dateien
    • Hamburg – Jetzt in echt und mit Bildern
  • Tags

    Addon Amerika Apple Auto bahn bild Computer dell Deutschland eisdiele Extension fahrrad Film firefox flash geburtstag google Indiana indianapolis Internet itunes Java Javascript junit kaputt karlsruhe Kino Kinofilm Laptop last.fm Linux Microsoft Mozilla PHP Praxissemester skype Spass system Thunderbird umzug USA windows wohnung Wordpress Zoll
  • Links

    • almightyfish - A new world order
    • DPSG Stamm Holzgerlingen - Die Homepage des Pfadfinderstamms der DPSG Holzgerlingen
    • eisdiele’s blog - Der Blog eines tollen Typs. Ich mein, er ist Pfadfinder, solche Leute sind per se einfach spitze …
    • Jule’s Blog - Ein Blog von der Jule :) in good ol’ Karlsruhe
    • Stephan’s Blog - Ein Komolitone

Powered by Wordpress | WP Premium theme by Premium Wordpress Themes
Copyright 2010 schwobeseggl.de. All rights reserved

  • Artikel
  • Fotos
  • Impressum