Bernardo

Hi all,

I have currently written and BHO (C#) and I need add custom attributes to <HTML> tag. My code looks like:

IHTMLElementCollection htmls = document.getElementsByTagName("HTML");

foreach (HTMLHtmlElement html in htmls)

{

html.setAttribute("xmlns;custom", "urn;schemas-microsoft-com", 0 );

html.setAttribute("xmlns;o", "urn;schemas-microsoft-com;office;office", 0);

}

...but it does not work

What am I doing wrong

(I used semicolons in post to not include emoticons)

Best regards,

Bernardo


Re: Internet Explorer Extension Development BHO HTML tag attributes

John Sudds - MSFT

Try this:

Smiley Free Zone

document.documentElement.setAttribute("xmlns:custom","urn:schema-microsoft-com",0);

The documentElement property is part of the IHTMLDocument3 interface. It's available on IE only, but as you're writing a BHO that shouldn't be an issue.






Re: Internet Explorer Extension Development BHO HTML tag attributes

Bernardo

OK. But how can I apply this to a specific element in the document

Lets say I want to apply to all DIV-s elements style="color: red".

Please help - I¡¯ve tried everything.





Re: Internet Explorer Extension Development BHO HTML tag attributes

John Sudds - MSFT

That's changing the subject somewhat.

DIV elements are different than the HTML element, which gets special handling as the root element.

Unfortunately, setAttribute in IE is a little screwy. It doesn't work on many attributes that you might want to set. In the case of style, the function returns without an error, but nothing happens. Instead, you must use the style object to make changes, as follows:

Code Snippet
var col = document.getElementsByTagName('DIV');
for (var i=0; i<col.length; i++)
{
col[i].style.color = "red";
}

Similar things happen with the class attribute (which must be changed with className) or the event attributes.






Re: Internet Explorer Extension Development BHO HTML tag attributes

Bernardo

OK. Sorry for changing the subject.

I just thought that if I manage to change/set/insert attributes in other ¡®simple¡¯ tags then I will try with <HTML> tag.

My fault.

That¡¯s my first IE add-on, usually I work on other projects in C#, ASP .NET and SQL related like Analysis and Reporting Services. That is why I need a help. I nearly finished with this project ¨C only this ¡®small¡¯ detail. Thanks a lot in advance for this conversation.

Problem stays the same - <HTML> tag
How BHO will ¡®know¡¯ where/into which tags insert it.
I tried your previous code without results.

Best regards,
Bernardo





Re: Internet Explorer Extension Development BHO HTML tag attributes

unique_username

Regarding the .setAttribute() being "a little screwy" in IE, it is indeed!

There's actually several bugs in this method, check the site below for more details (and workarounds)

All .setAttribute bugs:
http://webbugtrack.blogspot.com/2007/08/bug-242-setattribute-doesnt-always-work.html

Specifically the style .setAttribute bug:
http://webbugtrack.blogspot.com/2007/10/bug-245-setattribute-style-does-not.html


In the case of setting style, you can do this instead:

yourElement.style.setAttribute('cssText', 'color:red;');

Note that you are calling it on the "style" member, not the Element itself. ;-)