开发者

Use JavaScript/jQuery to manipulate image link url?

开发者 https://www.devze.com 2023-02-07 15:20 出处:网络
SharePoint won\'t let me set the relative URL I want to us开发者_开发知识库e for a link so I\'ll have to use jQuery/JavaScript instead to manipulate the URL.

SharePoint won't let me set the relative URL I want to us开发者_开发知识库e for a link so I'll have to use jQuery/JavaScript instead to manipulate the URL.

Let's say I am at

http://subsite.mysite.com/sites/department X/class/SitePages/Home.aspx

And on this site I have an image with a link which I want to take me to (skip class in the URL)

http://subsite.mysite.com/sites/department X/SitePages/Home.aspx

On another site

 http://subsite.mysite.com/sites/department Y/class/SitePages/Home.aspx

I want to be taken to

http://subsite.mysite.com/sites/department Y/SitePages/Home.aspx

To do this I was thinking about getting the current path with javascript, split on /, count the length of the array and remove what's between the third and second / from the right (class) and then build the URL again but is this the best way to go or is there a better way to do it?

Cheers

Edit: maybe I tried to achieve it in a way to difficult way now, it's just that if I set the url using the sharepoint gui with a relative path like ../sitepages/home.aspx or whatever sharepoint overrides this on save and set the full url. However, instead of having to split and stuff I can just change the url to the relative on with javascript.


Use String.replace() with a regex that will match your urls. For example, this might work for you:

link.href = link.href.replace(/\/[^\/]+\/SitePages\//, "/SitePages/");
0

精彩评论

暂无评论...
验证码 换一张
取 消