Discussion Forums  >  WebViews and HTML for Mobile

Replies: 7    Views: 110

farcat
buzztouch Evangelist
Profile
Posts: 1008
Reg: Jan 27, 2012
France
13,230
06/05/13 05:36 AM (10 years ago)

Url link leading to a particular location on webpage

Hi, Just wondering. With the custom url plugin is it possible to link to a particular spot on a webpage? For a webpage an ID or anchor tag can be used to direct to a particular place on a website, example: http://livingedge.com.au/#newsletter-signup I have targeted the "newsletter-signup" ID so the site opens at the bottom. This doesn't work with an app. I assume that it has to do with syntax of the link. Anybody knows how to make it work? Cheers, Farcat
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
06/05/13 05:53 AM (10 years ago)
This might work for you: [webview stringByEvaluatingJavaScriptFromString: @"window.location.hash='#newsletter-signup'"]; Stolen from this StackOverflow post: http://stackoverflow.com/questions/760584/how-to-reference-html-anchor Cheers! -- Smug
 
Annonymous
Profile
06/05/13 06:41 AM (10 years ago)
Thanks Smug! It worked like a charm, just needed to add that string to the webViewDidFinishLoad method. Cheers, Farcat
 
farcat
buzztouch Evangelist
Profile
Posts: 1008
Reg: Jan 27, 2012
France
13,230
like
02/25/14 02:33 PM (10 years ago)
Hi Smug, I am working on another app and I would like to use this same anchor method above BUT: - I set up the link to open in Launch Native App plugin (copyright issues). In which file do you think I should paste the code above for this plugin? - what do you think would be the correct syntax if I wanted to use more than one ID? I have tried a few combinations but none worked. Thanks for your guidance. Farcat
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
02/25/14 03:26 PM (10 years ago)
Forgive me; I'm trying to understand your situation, but I don't quite get it. Can you explain a little more? Maybe my light bulb will illuminate… Cheers! -- Smug
 
farcat
buzztouch Evangelist
Profile
Posts: 1008
Reg: Jan 27, 2012
France
13,230
like
02/26/14 01:19 AM (10 years ago)
You are all forgiven! Usually you are quite good at guessing my cryptic questions :) Must be my accent... Right, what I am trying to do is open an online webpage directly on an anchor (in this case an ID, instead of the top of the page). I have managed that before thanks to your post and the stackoverflow link by adding the following code in the webViewDidFinishLoad method of the BT_screen_customURL.m file: [webview stringByEvaluatingJavaScriptFromString:@"window.location.hash='#newsletter-signup'"]; That was because I was using the custom URL plugin, however I now want to do the same thing but using the Launch Native App plugin (so the link opens outside the app). So my first question is: where would you say the snippet goes? My second question is: what is the correct syntax if I want to point to two different anchors (on two different screens)? I hope that it makes more sense. Cheers, Farcat
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
02/28/14 08:31 PM (10 years ago)
Sorry it's been a while. And I'm not sure if what I 'suggest' will work… But it stands to reason it has a chance… "If" you're familiar with HTML, then in the 'destination' document, you'll need to place an anchor where you want it to be. In the CustomURL link, you'll need to address the 'anchor' in the URL… for instance: (Inside your HTML Document, where you want the page to 'show') <a id="anchor1">This is my Anchor</a> Then, in your CustomURL link: http://www.yourserver.com/desiredPage.html#anchor1 Hope this helps! Cheers! -- Smug
 
farcat
buzztouch Evangelist
Profile
Posts: 1008
Reg: Jan 27, 2012
France
13,230
like
03/03/14 02:08 AM (10 years ago)
Hi Smug, no worries, i know you are busy. I am familiar with HTML and I would indeed use this for a website. Unfortunately it doesn't work with an IOS app, it seems we need to tweak the code in the app first. This is not hugely important for the app I am currently developing, it would have been a good bonus though :) I'll research some more and will post if I get it to work. Cheers, Farcat
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.