Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var url = document.createElement('a');
- url.href = "http://www.example.com/some/path?name=value#anchor";
- var protocol = url.protocol;
- var hash = url.hash;
- alert('protocol: ' + protocol);
- alert('hash: ' + hash);
- var url = document.getElementById('myanchorid');
- window.location.href = "http://www.google.com";
- window.open('http://www.example.com');
- <a href="http://www.google.com" id="mylink">Visit Website</a>
- document.getElementById("mylink").href = "http://www.yahoo.com";
- var x = new Location('https://joe:secret@example.com:8080/path?q=test#hash');
- console.info(x.protocol); // > 'https:'
- console.info(x.hostname); // > 'example.com'
- console.info(x.port); // > '8080'
- console.info(x.pathname); // > '/path'
- console.info(x.search); // > '?q=test'
- console.info(x.hash); // > '#hash'
- x.href = 'http://www.example.org/wow'
- console.info(x.protocol); // > 'http:'
- console.info(x.hostname); // > 'www.example.org'
- console.info(x.port); // > ''
- console.info(x.pathname); // > '/wow'
- console.info(x.search); // > ''
- console.info(x.hash); // > ''
- x.on('change', function(){
- console.info(this.href);
- })
- x.href= 'https://stackoverflow.com' // > 'https://stackoverflow.com'
- interface URL {
- hash: string;
- host: string;
- hostname: string;
- href: string;
- readonly origin: string;
- password: string;
- pathname: string;
- port: string;
- protocol: string;
- search: string;
- username: string;
- readonly searchParams: URLSearchParams;
- toString(): string;
- }
- var url = new URL('http://localhost:8081/route1/route2?q=test#route3/route4');
- {
- hash: "#route3/route4"
- host: "localhost:8081"
- hostname: "localhost"
- href: "http://localhost:8081/route1/route2?q=test#route3/route4"
- origin: "http://localhost:8081"
- password: ""
- pathname: "/route1/route2"
- port: "8081"
- protocol: "http:"
- search: "?q=test"
- searchParams: URLSearchParams {}
- username: ""
- }
Add Comment
Please, Sign In to add comment