Replace domain in href using javascript in SharePoint
I am currently developing a jquery function which I intend to use to replace url gates -> http://mydomain:20000
As you know SharePoint use a usercontrol to embed the globalnavigation, and when rendered as HTML you find "/Subsite/Folder/Page.aspx" in the anchors tags' href.
My problem her开发者_如何学Pythone is that my colleague has managed to develop a cross-site navigation for a costumer, and that costumer also has a MySite which uses this cross-site navigation and MySites usually resides on another gate entry, in my case gate 20000.
So in order for the users to navigate around without getting 403 errors just because the cross-site navigation doesn't remove the :20000 entry I want to use a jquery script to remove that entry. Only problem - Don't know how.
A scrapped version:
<script type="text/javascript">
$(document).ready(function () {
var urlContain = new RegExp(':20000');
$('#s4-topheader2 a').each(function () {
var href = this.getAttribute('href').replace(urlContain, '');
$(this).attr('href', href);
});
});
</script>
It works as intended, but unfortunately, it doesn't remove the :20000 from the domain, as I mentioned earlier, the anchors only seems to contain "/Subsite/Folder/Page.aspx" when rendered. Though when I hover over them, I can see in the bottom left corner of my browser that it contains the domain name, but not when I View source.
Ideas and thoughts to solve this are highly appreciated.
If the URL is "/Subsite/Folder/Page.aspx"
as you say, then your browser will show the full address in the bottom left (as you say). This is because the URL "Subsite/Folder/Page.aspx"
is an address relative to the current domain.
This means that if that page is accessed from
www.example.com it will show www.example.com/Subsite/Folder/Page.aspx
www.example.com:8080 -> www.example.com:8080/Subsite/Folder/Page.aspx
www.example.com:2000 -> www.example.com:2000/Subsite/Folder/Page.aspx
etc.
By the sounds of it your javascript there is irrelevant, because there's no domain:port
in the URL to start with.
You options are:
- Add the domain (without the port) to the URLs. There's plenty of examples online on how to get just the domain part of the current page. You would then use a modified version of your current javascript to add the new domain (with http://) to the start of each URL.
- Change the entry gate that the other site uses so that it uses the correct domain:port. I don't completely understand your situation here, or your setup. But hopefully this makes enough sense for you to fit it to your needs.
精彩评论