URL - Web APIs | MDN

文章推薦指數: 80 %
投票人數:10人

URL. Experimental: 這是一個實驗中的功能此功能在某些瀏覽器尚在開發中,請參考兼容表格以得到不同瀏覽器用的前輟。

URL 介面提供了建立 URL 物件的靜態方法。

SkiptomaincontentSkiptosearchSkiptoselectlanguage給開發者的網頁技術文件WebAPIsURLChangelanguageViewinEnglishThispagewastranslatedfromEnglishbythecommunity.LearnmoreandjointheMDNWebDocscommunity.屬性建構式方法靜態方法規範瀏覽器相容性參見URLExperimental:這是一個實驗中的功能此功能在某些瀏覽器尚在開發中,請參考兼容表格以得到不同瀏覽器用的前輟。

URL 介面提供了建立URL 物件的靜態方法。

使用尚未實作此物件的瀏覽器時,可以改用 Window.URL(en-US)屬性來呼叫(基於Webkit或Blink引擎的瀏覽器可使用 Window.webkitURL)。

Note:ThisfeatureisavailableinWebWorkers 屬性 URL.href(en-US) IsaDOMStringcontainingthewholeURL. URL.protocol(en-US) IsaDOMStringcontainingtheprotocolschemeoftheURL,includingthefinal':'. URL.host(en-US) IsaDOMStringcontainingthehost,thatisthehostname,a':',andtheportoftheURL. URL.hostname(en-US) IsaDOMStringcontainingthedomainoftheURL. URL.port(en-US) IsaDOMStringcontainingtheportnumberoftheURL. URL.pathname(en-US) IsaDOMStringcontaininganinitial'/'followedbythepathoftheURL. URL.search(en-US) IsaDOMStringcontaininga'?'followedbytheparametersoftheURL. URL.hash(en-US) IsaDOMStringcontaininga'#'followedbythefragmentidentifieroftheURL. URL.username(en-US) IsaDOMStringcontainingtheusernamespecifiedbeforethedomainname. URL.password(en-US) IsaDOMStringcontainingthepasswordspecifiedbeforethedomainname. URL.origin(en-US)Readonly ReturnsaDOMStringcontainingtheoriginoftheURL,thatisitsscheme,itsdomainanditsport. URL.searchParams(en-US) ReturnsaURLSearchParams(en-US)objectallowingtoaccesstheGETqueryargumentscontainedintheURL. 建構式 URL()(en-US) CreatesandreturnaURLobjectcomposedfromthegivenparameters. 方法TheURLinterfaceimplementsmethodsdefinedinURLUtils. URLUtils.toString() ReturnsaDOMStringcontainingthewholeURL.ItisasynonymforURLUtils.href,thoughitcan'tbeusedtomodifythevalue. 靜態方法 URL.createObjectURL() ReturnsaDOMStringcontainingauniqueblobURL,thatisaURLwithblob:asitsscheme,followedbyanopaquestringuniquelyidentifyingtheobjectinthebrowser. URL.revokeObjectURL()(en-US) RevokesanobjectURLpreviouslycreatedusingURL.createObjectURL(). 規範 Specification Status Comment FileAPIThedefinitionof'URL'inthatspecification. WorkingDraft AddedthestaticmethodsURL.createObjectURL()andURL.revokeObjectURL(). URLThedefinitionof'Node'inthatspecification. LivingStandard Initialdefinition(implementsURLUtils). 瀏覽器相容性We'reconvertingourcompatibilitydataintoamachine-readableJSONformat. Thiscompatibilitytablestillusestheoldformat, becausewehaven'tyetconvertedthedataitcontains. Findouthowyoucanhelp!(en-US) Desktop Mobile Feature Chrome Edge Firefox(Gecko) InternetExplorer Opera Safari Basicsupport 8.0[2] 32 ? 4.0(2.0)[1][3] 19.0(19.0) 10.0 15.0[2] 19 6.0[2] 7.0 username,password,andorigin 32 ? 26.0(26.0) ? 19 (Yes) searchParams 49 ? 29.0(29.0) ? 36 No support Feature Android ChromeforAndroid FirefoxMobile(Gecko) IEMobile OperaMobile SafariMobile Basicsupport 4[2] 4.4 8.0[2] 32 14.0(14.0)[1][3] 19.0(19.0) (Yes) 15.0[2] 6.0[2] username,password,andorigin 4.4 32 26.0(26.0) ? ? (Yes) searchParams No support 49 29.0(29.0) ? ? ? [1]FromGecko2(Firefox4)toGecko18included,Geckosupportedthisinterfacewiththenon-standardnsIDOMMozURLPropertyinternaltype.Astheonlytoaccesssuchanobjectwasthroughwindow.URL(en-US),inpractice,thisdidn'tmakeanydifference. [2]Thisfeatureisimplementedunderthenon-standardnamewebkitURL. [3]ForFirefox,tousefromchromecode,JSMandBootstrapscope,youhavetoimportitlikethis: Cu.importGlobalProperties(['URL']); URLisavailableinWorkerscopes.參見 Propertyallowingtogetsuchanobject:Window.URL(en-US). Components.utils.importGlobalProperties Foundaproblemwiththispage?EditonGitHubSourceonGitHubReportaproblemwiththiscontentonGitHubWanttofixtheproblemyourself?SeeourContributionguide.Lastmodified:Dec10,2021,byMDNcontributorsChangeyourlanguageSelectyourpreferredlanguage正體中文(繁體)DeutschEnglish(US)EspañolFrançais日本語한국어Português(do Brasil)Русский中文(简体)ChangelanguageRelatedTopicsURLAPIURLConstructorURL()PropertieshashhosthostnamehreforiginpasswordpathnameportprotocolsearchsearchParamsusernameMethodscreateObjectURL()revokeObjectURL()toJSON()toString()RelatedpagesforURLAPIURLSearchParams



請為這篇文章評分?