2016-03-20 22 views

答えて

4

URLを指定すると、URL constructorを解析してそれを解析し、parsed URL componentsを抽出することができます。例えば:

// Just an example, there are many ways to get a URL in an extension... 
 
var url = 'http://example.com:1234/test?foo=bar#hello=world'; 
 
var parsedUrl = new URL(url); 
 
console.log(parsedUrl.host); 
 

 
// Or if you want a one-liner: 
 
console.log(new URL(url).host);
Open the JavaScript console, and you'll see "example.com:1234" (2x).

+0

残念それはIEといくつかの携帯電話のブラウザでは安定しないので、それは、クロスブラウザの機能ではありませんが、それは私の現在の目的を果たしていること。ありがとうございました。 – Pasaribu

関連する問題