• 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: Using an anchor in NSURL file url
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using an anchor in NSURL file url


  • Subject: Re: Using an anchor in NSURL file url
  • From: email@hidden
  • Date: Fri, 22 Jan 2016 11:25:03 +0100
  • Importance: Normal

Would it be possible to parse the anchor out from the url and then once
the page is completely loaded in the webview use javascript's
window.location to jump to the anchor's location within the page. I know
that can work for UIWebView, not 100% sure for WKWebView.




> On Jan 21, 2016, at 7:17 PM, Jeff Evans <email@hidden> wrote:
>>
>> Colleagues,
>>
>> 	In OSX I'm using an NSURLRequest to load a file url in WKWebView. Works
>> fine unless I try to add an anchor to the path, for example,
>>
>> [path]/filename.html#anchorname
>
> The most correct way would be to use NSURLComponents to append the
> fragment:
>
> NSURL* fileURL = [NSURL fileURLWithPath:somePathString]; // or, even
> better, an API that gives file URLs directly, skipping the path string
> NSURLComponents* components = [NSURLComponents componentsWithURL:fileURL
> resolvingAgainstBaseURL:YES];
> components.fragment = @"anchorname";
> NSURL* urlWithFragment = components.URL;
>
>
> If you can't use NSURLComponents because you're targeting releases of OS X
> before 10.9, you should just use string operations:
>
> NSURL* fileURL = // … as above …
> NSString* urlString = fileURL.absoluteString;
> urlString = [urlString stringByAppending:@"#anchorname"];
> NSURL* urlWithFragment = [NSURL URLWithString:urlString];
>
> Regards,
> Ken
>
>
> _______________________________________________
>
> 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

_______________________________________________

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: 
 >Using an anchor in NSURL file url (From: Jeff Evans <email@hidden>)
 >Re: Using an anchor in NSURL file url (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Faster scrolling after resizing window
  • Next by Date: Re: How to record screen in iOS
  • Previous by thread: Re: Using an anchor in NSURL file url
  • Next by thread: adding frameworks to my project
  • Index(es):
    • Date
    • Thread