what is this strange "script" doing?

I am doing some test then find below code would pop up a window:

<a href="script:test">test</a>

looks like it is trying to open an application. Can anyone tell me what is the usage/purpose of this "script"? looks like FF, Chrome, and IE all support it.

2 answers

  • answered 2017-11-14 23:40 Flamma

    Trying to open an application? That script is just a hyperlink, it does not tell anything else in the script, just that it will open a link into site that tells "test"

  • answered 2017-11-14 23:44 Blender

    script is being used as a protocol. No applications handle the script protocol, so clicking it does nothing useful.

    You can register a custom protocol handler and if the user accepts it, your application will be allowed to open all links of that type (there are only a few permitted protocols):

    window.navigator.registerProtocolHandler('web+test', 'http://example.org/?handler=%s', 'Test Protocol');
    

    Only example.org will be allowed to run the above code, but if you open your dev tools while visiting http://example.org/ and run the above code, you will get a dialog asking you to allow or deny the protocol association. If you accept it, click the following link on any website:

    <a href="web+test:hello">test</a>
    

    It will redirect to http://example.org/?handler=hello