in javascript
、与えられた有効なurl
、たとえば、
http://seeplai2.trailsandtribulations.nat/admin/items?var=val#here
にあるオリジン、パス名、検索、およびハッシュを抽出する式は何window.location
ですか?
で比較的弱いregx
ので、ここに私の推測があります:
origin: href.match(/(.*?)(\/|\?|#))[1]
pathname: href.match(\/\/[^\/]*([^\?#]*)/)[1]
search: (href.indexOf('?')>-1) ? href.match(/\?[^#]*)/)[1] : ''
hash: (href.indexOf('#')>-1) ? href.match(/(#.*)/)[1] : ''
これらは正しく見えますか?
サンプルコードは次のとおりです。
<a href='/path?var=val1' onclick='doClick(event)'>Anchor1</a>
function doClick(e) {
var href = e.target.href;
var origin = href.match(/regx/)[1];
// if different origin, go there
if( origin != window.location.origin ) return;
// if only hash difference, let default take over
...
// if path different, process here
...
}