Re: How can I get the 'width' and 'height' of an

Jonas Sicking <[email protected]>
Newsgroups gmane.comp.mozilla.devel.dom
Message-ID <[email protected]>
[email protected] wrote:
> Hi,
> 
> I use the following code to get and print the width and height
> attribute of a nsIDOMNSHTMLElement.
> 
> But I only get 'empty' string.   I am sure that the source has 'width'
> and 'height' attribute.  Can you please tell me what am i missing?
> 
> Thank you.
> 
> 
>     nsIDOMNSHTMLElement* element;
> 
>    nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(element);
> 
>     if (domElement) {
>       nsAutoString width;
>       nsAutoString height;
> 
>       domElement->GetAttribute(NS_LITERAL_STRING("width"), width) ;
>       domElement->GetAttribute(NS_LITERAL_STRING("height"), height) ;
> 
>       printf("w:%s:\n", width.get());
>       printf("h:%s:\n", height.get());
> 
> }

nsAutoStrings are UTF16, printf expects an ASCII string. Try doing

printf("w:%s:\n", NS_LossyConvertUTF16toASCII(width).get());

Do note that this won't properly print non-ascii characters, but I don't 
think there is a way to get printf to do so.

/ Jonas
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.