javascript - Set origin when parsing HTML document -


my javascript app retrieves webpage xhr parses this:

        var el = document.createelement( 'html' );         el.innerhtml = xml;          var links = el.getelementsbytagname( 'a' ); 

in process, links' href tags reinterpreted relative this document, links http://localhost:8000/download.zip.

i tried hacking way around it:

if (link.origin === document.origin) {     link.href = link.href.replace(link.origin, h.url.replace(/\/$/, '')); } 

but can't distinguish between foo.org/bar (foo.org/bar/download.zip) , foo.org/bar.php (foo.org/download.zip), , don't want go down rabbit hole of working out substitutions perform.

i tried injecting either <base href=...> or <xml:base=xxx> document, didn't work.

what missing? seems common enough need?

i'm not using jquery or similar (and can't.)


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -