For example, I provide an relative to an social sharing plugin
../../test.html
as a link
It show as
http://../../test.html
Is there any way to convert the path to absolute if it requires an "http://" before the path ? Thanks
Edit:
The place I put the path
$('#sina').attr('href', "javascript:void((function(s,d,e,r,l,p,t,z,c){var%20f='.php?appkey=',u=z||d.location,p=['&url=',e(u),'&title=',e(t||d.title),'&source=',e(r),'&sourceUrl=',e(l),'&content=',c||'gb2312','&pic=',e(p||'')].join('');function%20a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=440,height=430,left=',(s.width-440)/2,',top=',(s.height-430)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent,'','','" + imgStr + "','" + shareDes + "','','utf-8'));");
I dont know how the path works but it works if I provide with absolute path
#sina
is a <a href></a>
element while imgStr is the link provide
I check the source code after running the website , if it is relative path , it show as "http://../../test.html"
For example, I provide an relative to an social sharing plugin
../../test.html
as a link
It show as
http://../../test.html
Is there any way to convert the path to absolute if it requires an "http://" before the path ? Thanks
Edit:
The place I put the path
$('#sina').attr('href', "javascript:void((function(s,d,e,r,l,p,t,z,c){var%20f='http://v.t.sina..cn/share/share.php?appkey=',u=z||d.location,p=['&url=',e(u),'&title=',e(t||d.title),'&source=',e(r),'&sourceUrl=',e(l),'&content=',c||'gb2312','&pic=',e(p||'')].join('');function%20a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=440,height=430,left=',(s.width-440)/2,',top=',(s.height-430)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent,'','','" + imgStr + "','" + shareDes + "','','utf-8'));");
I dont know how the path works but it works if I provide with absolute path
#sina
is a <a href></a>
element while imgStr is the link provide
I check the source code after running the website , if it is relative path , it show as "http://../../test.html"
- 2 I'm afraid your question is very unclear. You provide the relative path where? What does that markup/code look like? "It show as..." Where? What are you looking at? – T.J. Crowder Commented Aug 22, 2013 at 8:18
- What is the server side platform? – gdoron Commented Aug 22, 2013 at 8:19
- Thanks for the reply, sorry for unclear , let me edit it – user1871516 Commented Aug 22, 2013 at 8:19
-
This sounds like a problem with the plugin, it's adding the
http://
prefix, so your relative path bees absolute. – Barmar Commented Aug 22, 2013 at 8:20 - @Barmar you are correct , Is the workaround replace ../ to location.href or something similiar? – user1871516 Commented Aug 22, 2013 at 8:28
1 Answer
Reset to default 3Try
location.hostname+location.pathname+your_relative_path
This will give you a bination of the path to your current page (minus the actual file name if there was one in the url) with your relative address in your_relative_path
.
So, something like http://www.mypage./contents/level1/en-us/page2/../../test.html
would be the result in the end.