javascript - Reference or find unidentified parent element from within that element -


if question cannot answered, i'm going post second, "fall back" question. have been writing javascript jsonp type apps client has insert single javascript line wherever want app show on web page. far it's work out pretty well, want add 1 more variable js src attribute, , present client's page url.

before:

<script id="myscript" type="text/javascript" src="http://www.mydomain.com/scripts/ds.js?cid=00000001&domain=clientdomain.com"></script> 

but new twist, want add page url variable in src, so:

<script id="myscript" type="text/javascript" src="http://www.mydomain.com/scripts/ds.js?cid=00000001&domain=clientdomain.com&page="+document.url></script> 

if document.url placed between script tag, can (but leads me have write larger , less elegant code block). maybe javascript not allowed in attribute parameters of tag, itself.

the usual way build tag in javascript. can added benefit of asynchronous loading (although can problem if don't know how handle asynchronous loading properly). example:

<script>     (function(d){         var f=d.createelement('script'),s=d.getelementsbytagname('script')[0];         f.type='text/javascript';         f.async=true;         f.src='http://www.mydomain.com/scripts/ds.js?cid=00000001&domain=clientdomain.com&page='+encodeuri(document.location.href);         s.parentnode.insertbefore(f,s)     })(document) </script> 

google analytics uses similar code you're in company. , you're quite right can't directly inside html tag.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -