Is "javascript:function()" a URL?
Going through the WebView demo, I noticed the following statement:
mWebView.loadUrl("javascript:wave()");
It works, but I don't understand the syntax. Why does the "javascript:function()" work as a URL 开发者_如何学Goparamter to WebView.loadUrl() ?
Yes, although not very far along the standards track: https://datatracker.ietf.org/doc/html/draft-hoehrmann-javascript-scheme-03
The return value of the function should be the document to be rendered.
It is the same like <a href="javascript:alert('test')">link text</a>
Your browser knows that this is javascript and starts the named function.
Yes it is a url that defines some javascript functionality to be run within the global scope of the current page.
It is the way bookmarklets work
if you know the notion of "overloading" something, think of it that way. The browser is designed to examine the string that you put in the address bar (or pass as an href) and if it starts with the string literal "javascript:" it knows to execute what follows as javascript, rather than treating it as a URL.
This is called Bookmarklet.
Here are some examples: http://www.bookmarklets.com/
精彩评论