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


#1

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.


#2

Any help? …20 chars.


#3

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


#4

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!


#5

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


#6

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 !