[Solved]WebBrowserComponent::goToURL() doesn't support anchor link

If a link include ‘#’ (anchor link), goToURL() won’t load, open and position it in WebBrowserComponent.

This issue only appears on macOS, haven’t tested on Linux yet.

Any help? …20 chars.

This might help troubleshoot: http://stackoverflow.com/a/37771617

1 Like

Seems the exactly problem I encountered. That gentleman said he used JavaScript to scroll the web page:

[webView stringByEvaluatingJavaScriptFromString:[NSString swf:@"window.location.hash='%@';",anchorName]];

To my shame, Swift language is so strange to me and I only know a little about JavaScript. So, anyone could kindly translate the sentence above to JUCE C++?

Thanks!

Wait a minute… perhaps I could solve this problem myself…

Solved!!
Here is the code, hope this’ll help someone.

#if JUCE_MAC
    webBrowserComponent->goToURL ("javascript:location.hash=\"" + anchorStr + "\";");
#else
    webBrowserComponent->goToURL (currentUrl + "#" + anchorStr);
#endif

Thank you, @jrlanglois !