jQuery plugin making a API url relative to included js file rather than host -


hi working on jquery plugin in make api call. rather hard coding url api, relative in terms of url of js file of plugin

so have following set up

page loading file

http://mydomain1.com 

in page load

<script src="http://mydomain2.com/scripts/myplugin.min.js"> 

in js file, load api url

api_endpoint: "/myapi/api/v1", 

i hoping resolve to

http://mydomain2.com/myapi/api/v1 

but resolves to

http://mydomain1.com/myapi/api/v1 

is there anyway in javascript can set domainname relative js file loading script rather page ?

as per understanding of problem, want url of external file base url. can use below code access that:

  1. captured script files of document
  2. defined index script file , refined query string url
  3. now used split , slice remove last directory name(folder name) , join make complete url

...

var scripttags = document.getelementsbytagname('script'); var filterpath = scripttags[0].src.split('?')[0];      // hopping script on first place of dom , removing ?query var scriptfilepathurl = filterpath.split('/').slice(0, -1).join('/'); alert(scriptfilepathurl); 

Comments