| <html> |
| <head> |
| <title>Protocol Handler Test - Register</title> |
| <script type="text/javascript"> |
| function registerCustomHandler() { |
| var custom_protocol = "web+search"; |
| var query_value = custom_protocol + ":test"; |
| var query_key = "q"; |
| var url = document.URL + "?" + query_key + "=%s"; |
| var title = "Example Search"; |
| |
| navigator.registerProtocolHandler( |
| custom_protocol, url, title); |
| var element = document.getElementById('test_protocol'); |
| element.innerText = query_value; |
| element.setAttribute('href', query_value); |
| |
| return {"protocol": custom_protocol, "url": url, "title": title, |
| "query_key": query_key, "query_value": query_value}; |
| } |
| |
| function registerMailClient() { |
| var mail_protocol = "mailto"; |
| var query_value = mail_protocol + ":example@examplemail.com"; |
| var query_key = "source"; |
| var url = document.URL + "?" + query_key + "=%s"; |
| var title = "ExampleMailClient"; |
| |
| navigator.registerProtocolHandler(mail_protocol, url, title); |
| return {"protocol": mail_protocol, "url": url, "title": title, |
| "query_key": query_key, "query_value": query_value}; |
| } |
| |
| // Analyzes the query substring (if any) of the URL and confirms |
| // whether it's expected. |
| function doesQueryConformsToProtocol(query_key, query_value) { |
| var query = window.location.search.substring(1); |
| var arg_list = query.split("&"); |
| |
| if(arg_list.length != 1) return false; |
| var variable_value = arg_list[0].split("="); |
| if((variable_value[0] != query_key) || |
| (unescape(variable_value[1]) != query_value)) |
| return false; |
| return true; |
| } |
| </script> |
| </head> |
| <body> |
| <div> |
| <a id="test_protocol"></a> |
| </div> |
| <div> |
| <a id="test_mail_protocol" href="mailto:example@examplemail.com">mailto:example@examplemail.com</a> |
| </div> |
| </body> |
| </html> |