Guest User

Untitled

a guest
Nov 24th, 2017
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. var url = document.createElement('a');
  2. url.href = "http://www.example.com/some/path?name=value#anchor";
  3. var protocol = url.protocol;
  4. var hash = url.hash;
  5.  
  6. alert('protocol: ' + protocol);
  7. alert('hash: ' + hash);
  8.  
  9. var url = document.getElementById('myanchorid');
  10.  
  11. window.location.href = "http://www.google.com";
  12.  
  13. window.open('http://www.example.com');
  14.  
  15. <a href="http://www.google.com" id="mylink">Visit Website</a>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
  16.  
  17. document.getElementById("mylink").href = "http://www.yahoo.com";
  18.  
  19. var x = new Location('https://joe:secret@example.com:8080/path?q=test#hash');
  20. console.info(x.protocol); // > 'https:'
  21. console.info(x.hostname); // > 'example.com'
  22. console.info(x.port); // > '8080'
  23. console.info(x.pathname); // > '/path'
  24. console.info(x.search); // > '?q=test'
  25. console.info(x.hash); // > '#hash'
  26.  
  27. x.href = 'http://www.example.org/wow'
  28. console.info(x.protocol); // > 'http:'
  29. console.info(x.hostname); // > 'www.example.org'
  30. console.info(x.port); // > ''
  31. console.info(x.pathname); // > '/wow'
  32. console.info(x.search); // > ''
  33. console.info(x.hash); // > ''
  34.  
  35. x.on('change', function(){
  36. console.info(this.href);
  37. })
  38.  
  39. x.href= 'https://stackoverflow.com' // > 'https://stackoverflow.com'
  40.  
  41. interface URL {
  42. hash: string;
  43. host: string;
  44. hostname: string;
  45. href: string;
  46. readonly origin: string;
  47. password: string;
  48. pathname: string;
  49. port: string;
  50. protocol: string;
  51. search: string;
  52. username: string;
  53. readonly searchParams: URLSearchParams;
  54. toString(): string;
  55. }
  56.  
  57. var url = new URL('http://localhost:8081/route1/route2?q=test#route3/route4');
  58.  
  59. {
  60. hash: "#route3/route4"
  61. host: "localhost:8081"
  62. hostname: "localhost"
  63. href: "http://localhost:8081/route1/route2?q=test#route3/route4"
  64. origin: "http://localhost:8081"
  65. password: ""
  66. pathname: "/route1/route2"
  67. port: "8081"
  68. protocol: "http:"
  69. search: "?q=test"
  70. searchParams: URLSearchParams {}
  71. username: ""
  72. }
Add Comment
Please, Sign In to add comment