4

I am writing a chrome extension that change part of the url in the current tab and reload the page with the modified url. I am wondering if there is a Javascript equivalent of the php's parse_url function. Currently, I have to write my own parser with regex to extract parts of the url; however, I would think that such function already exists in the in Javascript.

After researching for a bit, I believe I can get a location object with "window.location" and extracts the different components with "window.location.protocal" etc...

In chrome extension, however, calls to "window.location" would to return a url which I believe refers to the internal component of chrome instead of the page's url. Assuming I that get a reference to the "tab" object in chrome, I can access the tab's url string with tab.url. Since tab.url is just a string, I am hoping there is an internal method that can dissect the url for me instead of writing a custom function.

Thank you

Brett Zamir
  • 14,034
  • 6
  • 54
  • 77
defoo
  • 5,159
  • 11
  • 34
  • 39

2 Answers2

7

http://phpjs.org/functions/parse_url:485

renick
  • 3,873
  • 2
  • 31
  • 40
0

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

Pragnesh Chauhan
  • 8,363
  • 9
  • 42
  • 53
Ruslan
  • 1