Javascript equivalent php parse_url

I am writing a chrome extension that changes part of the URL on the current tab and reloads the page with the changed URL. I am wondering if there is a Javascript equivalent of the php parse_url function. Currently, I have to write my own regular expression parser to extract parts of the URL; however, I would think that such a function already exists in Javascript.

After a little research, I believe that I can get the location object with "window.location" and retrieve various components using "window.location.protocal" etc.

In the chrome extension, however, calls to "window.location" will return a URL that, it seems to me, refers to the internal chrome component instead of the page URL. Assuming I get a reference to the "tab" object in chrome, I can access the tab url using tab.url. Since tab.url is just a string, I hope there is an internal method that can parse the url for me instead of writing a custom function.

thanks

+4
source share
2 answers

In content scripts, chrome externsion window.location refers to page url

0
source

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


All Articles