Skip navigation.
 
mlHow can I access full source of a WebView
FROM : Ömer Karda?
DATE : Wed Oct 08 00:45:22 2008

Hi

I am trying to send the contents of a webwiew with email. I have found 
several ways to do that, but there are minor problems.

//    get the attributes string of the webview
   id res = (id <WebDocumentText> )[[[myWebView mainFrame] frameView] 
documentView];
   NSAttributedString *p = [res attributedString];
   NSPasteboard *pb = [NSPasteboard pasteboardWithName:@"PBtoMail"];

//    init a private pastebord for data transfer, this time use 
webarchive for transfer
   [pb declareTypes:[NSArray arrayWithObject:NSRTFDPboardType] 
owner:self];

//    convert the attributed string to rtfd and place it on the private 
pasteboard
   NSRange range;
   range.location = 0;
   range.length = [p length];
   [pb setData:(NSData *)[p RTFDFromRange:range documentAttributes:nil 
forType:NSRTFDPboardType];
   
//    open mail window using the rtfd data using services...
   NSPerformService(@"Mail/Send Selection", pb);
   
This works, but quality is no so good. So I tried a different approach

//    init a private pastebord for data transfer, this time use 
webarchive for transfer
   NSPasteboard *pb = [NSPasteboard pasteboardWithName:@"PBtoMail"];
   [pb declareTypes:[NSArray arrayWithObject:WebArchivePboardType] 
owner:self];

//    get the webarchive and place it on pboard
   [pb setData:[[[myWebView mainFrameDocument] webArchive] data] 
forType:WebArchivePboardType];

   NSPerformService(@"Mail/Send Selection", pb);

This works better. However external CSS code is not copied, which 
makes the page look different. When I select all and copy from the 
webview manualy and then paste it on a new mail window it works fine, 
the external CSS is copied as well. Is there any way I get the full 
source (including the external CSS) so that I can place it on the 
pasteboard?

Thanks in advance.

Related mailsAuthorDate
mlHow can I access full source of a WebView Ömer Karda? Oct 8, 00:45
mlRe: How can I access full source of a WebView Rob Keniger Oct 8, 01:13
mlRe: How can I access full source of a WebView Ömer Karda? Oct 8, 01:44