• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: stripped down webview
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stripped down webview


  • Subject: Re: stripped down webview
  • From: Koen van der Drift <email@hidden>
  • Date: Mon, 20 Aug 2012 09:20:45 -0400

D'oh, I just discoverd that the website I'd like to display has a
mobile version, which is already basic. I'll just display that instead
in my webView.  This only needs some minor tweaks to remove one or two
divs, and saves me a lot of headaches.

- Koen.




On Sun, Aug 19, 2012 at 10:00 AM, Koen van der Drift
<email@hidden> wrote:
> So for future reference, I figured out how to add my local javascript.
>
> This is what I do:
>
> - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
> {
>     if (frame == [sender mainFrame])
>     {
>         NSError *error = nil;
>
>         // get the DOMDocument
>         DOMDocument* domDocument = [frame DOMDocument];
>         DOMElement* headElement= (DOMElement*)[[domDocument getElementsByTagName: @"head"] item: 0];
>         // get the reference.js file
>         NSString *path = [[NSBundle mainBundle] pathForResource: @"test" ofType: @"js"];
>         NSString *js = [NSString stringWithContentsOfFile: path encoding: NSUTF8StringEncoding error: &error];
>
>         if (js && headElement && error = nil)
>         {
>             // create a script element
>             DOMElement* scriptElement = [domDocument createElement: @"script"];
>             [scriptElement setAttribute: @"type" value: @"text/javascript"];
>
>             // add the default css to it
>             DOMText *jsText = [domDocument createTextNode: js];
>             [scriptElement appendChild: jsText];
>
>             // add it to <head>
>             [headElement appendChild: scriptElement];
>         }
>     }
> }
>
>
> My test.js file looks like this:
>
> function test()
> {
>     document.write("<p>This is a test.</p>");
> }
>
> test();
>
>
> And all my webview shows is "This is a test".  It even picks up the css for the <p> element I declared in my custom css class! I didn't have to use stringByEvaluatingJavaScriptFromString, although it definitely was useful for debugging purposes.
>
>
> Next, changing the content by stripping out some divs.
>
>
> - Koen.
>
>
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >stripped down webview (From: Koen van der Drift <email@hidden>)
 >Re: stripped down webview (From: Kyle Sluder <email@hidden>)
 >Re: stripped down webview (From: Koen van der Drift <email@hidden>)
 >Re: stripped down webview (From: Matt Patenaude <email@hidden>)
 >Re: stripped down webview (From: Koen van der Drift <email@hidden>)
 >Re: stripped down webview (From: Matt Patenaude <email@hidden>)
 >Re: stripped down webview (From: Koen van der Drift <email@hidden>)
 >Re: stripped down webview (From: Koen van der Drift <email@hidden>)
 >Re: stripped down webview (From: Evadne Wu <email@hidden>)
 >Re: stripped down webview (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Re: Pass data through view
  • Next by Date: Re: How to (slowly) rotate a view
  • Previous by thread: Re: stripped down webview
  • Next by thread: Re: stripped down webview
  • Index(es):
    • Date
    • Thread