Check if userinput is a valid URI in XUL

Is there a built-in function / method that can check if a given string is a valid URI or not in the Mozilla XUL toolkit? I searched for one, but did not find any, but since this is my first time I used XUL and its documentation, maybe I just did not pay attention to it. So I just made sure before I started writing my own IsValidURI function.

+4
source share
1 answer

nsIIOService.newURI (...) is what you are looking for. It outputs NS_ERROR_MALFORMED_URI if the URI string is invalid.

Example:

 try { var ioServ = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var uriObj = ioServ.newURI(uriString, uriCharset, baseURI); } catch (e) { // catch the error here } 
+3
source

Source: https://habr.com/ru/post/1276481/


All Articles