Construction using window.location.href as base throws Invalid URL
See original GitHub issueWhen attempting to construct a URL using a relative path and a base argument matching the current document’s window.location.href
, an error TypeError: Invalid URL
is thrown.
Environment: IE10 Steps to reproduce:
new URL("/my/path", window.location.href)
(in my test my path was http://timelord.local:4200/candidates;location=martin_pl;date=2019-12-24
)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
window.location.href doesn't redirect - Stack Overflow
It will run the code in the function and then submit the page instead of redirect. In this case change the type tag...
Read more >Location href Property - W3Schools
The location.href property sets or returns the entire URL of the current page. Syntax. Return the href property: location.href.
Read more >URL() - Web APIs - MDN Web Docs - Mozilla
The URL() constructor returns a newly created URL object representing the URL defined by the parameters.
Read more >How to Check if a JavaScript String is a Valid URL
In JavaScript, you may need to use a URL in the anchor tags or buttons to link the user to another webpage. This...
Read more >URL objects - The Modern JavaScript Tutorial
So technically we don't have to use URL . But sometimes it can be really helpful. Creating a URL. The syntax to create...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I know, the polyfill doesn’t aim to be perfect BUT to be compact. Originally, the base parameter should only contains the origin. Nothing more. The spec evolved and now the base’s path minus last part must be prepend. Because of this evolution, IE cannot support all cases ! If you really need the full implementation: https://github.com/lifaon74/whatwg-url
But you could simply use something like:
Somehow, this could be patched in this polyfill. For this you could do a pull request.
Your welcome. I’ll close this issue. If you have any question you can re-open it.