Our Forum has Moved

This site is our old forum and is only here for achive until we get proper 301 redirects setup to make Google happy.

Please use our new community site - Our Umbraco - which contains an improved forum, documentation wiki, package repository and a member locator.

Go to Our Umbraco now

Learn everything about Umbraco
Hostnames -- Am I doing this right? Options
jHodgkinson
Posted: Friday, March 20, 2009 4:37:34 PM
Rank: Fanatic

Joined: 3/15/2007
Posts: 384
Location: Cary, NC USA
I rewrote the NiceUrl function to handle full domain replacements (I guess this is OK since I'm assuming v3.06 is the last official update in the 3.x release) unless Niels or anyone else feels everything works great and adds it to codeplex... anyways, from my initial testing this appears to work... we have a variety of sites in development and everything worked jumping back and forth across sites... just make sure you have useDomainPrefixes set to true... the NiceUrl method is located in the umbraco.library class.

also, on a side-note, we were pulling content (from online reuse content book) from one site into other sites and this is where we discovered the CMS inserted {localLink:XXX} links were not fully qualified even though we had the useDomainPrefixes set to true... we also needed to make sure our navigation links were fully-qualified using http references so that once on secure https page you could click on the navigation links and exit SSL mode...

Code:


        public static string NiceUrl(int nodeID)
        {
            try
            {
                    int startNode = 1;
                    if (GlobalSettings.HideTopLevelNodeFromPath)
                        startNode = 2;

                    string niceUrl = niceUrlDo(nodeID, startNode);
                    if (UmbracoSettings.UseDomainPrefixes)
                    {
                        //get current domain
                        string currentDomain = HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToLower();

                        //get target absolute path
                        string fullPath = NiceUrlFullPath(nodeID);

                        //create url from target absolute path
                        if (fullPath.Contains("http://") || fullPath.Contains("https://"))
                        {
                            //get full path
                            Uri url = new Uri(fullPath);

                            //get target domain
                            string targetDomain = url.Host;

                            //construct url
                            string absPrefix = "http://" + targetDomain;
                            if (absPrefix != niceUrl) //root page check
                                niceUrl = absPrefix + niceUrl;
                        }
                        else //local domain page
                        {
                            //construct url
                            string absPrefix = "http://" + umbraco.library.RequestServerVariables("SERVER_NAME");
                            if(absPrefix != niceUrl) //root page check
                                niceUrl =  absPrefix + niceUrl;
                        }
                    }

                    return niceUrl;
            }
            catch
            {
                return "#";
            }
        }


mathijsuitmegen
Posted: Wednesday, December 09, 2009 11:47:49 AM
Rank: Newbie

Joined: 12/9/2009
Posts: 2
You could solve this using JavaScript and custom stylesheet classes.

I assume you have two separate Web sites (Site A & Site B) in one umbraco installation. Each site exists within separate nodes just below the content node.

You will have to setup a custom Stylesheet. Give your new class a proper name and set the 'Alias' to '.hyperlink_siteB'.
Now in your content (page in Site A), apply the style to the hyperlink you want to point to Site B.

Now in your masterpage add the JavaScript block displayed below:

Code:
    <script type="text/javascript">
        function addLoadEvent(func) {
            var oldonload = window.onload;
            if (typeof window.onload != 'function') {
                window.onload = func;
            }
            else
            {
                window.onload = function()
                {
                    if (oldonload)
                    {
                        oldonload();
                    }
                    func();
                }
            }
        }

        addLoadEvent(function()
        {
            try
            {
                var elements = getElementsByClassName("hyperlink_siteB");
                for (var i = 0; i < elements.length; i++)
                {
                    var hyperlink = elements[i];
                    hyperlink.href = hyperlink.href.replace("http://www.siteA.com", "http://www.siteB.com");
                }
            }
            catch (ex){ }
        });
        
        /*
            Developed by Robert Nyman, http://www.robertnyman.com
            Code/licensing: http://code.google.com/p/getelementsbyclassname/
        */
        var getElementsByClassName = function (className, tag, elm){
            if (document.getElementsByClassName) {
                getElementsByClassName = function (className, tag, elm) {
                    elm = elm || document;
                    var elements = elm.getElementsByClassName(className),
                        nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
                        returnElements = [],
                        current;
                    for(var i=0, il=elements.length; i<il; i+=1){
                        current = elements[i];
                        if(!nodeName || nodeName.test(current.nodeName)) {
                            returnElements.push(current);
                        }
                    }
                    return returnElements;
                };
            }
            else if (document.evaluate) {
                getElementsByClassName = function (className, tag, elm) {
                    tag = tag || "*";
                    elm = elm || document;
                    var classes = className.split(" "),
                        classesToCheck = "",
                        xhtmlNamespace = "http://www.w3.org/1999/xhtml",
                        namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
                        returnElements = [],
                        elements,
                        node;
                    for(var j=0, jl=classes.length; j<jl; j+=1){
                        classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
                    }
                    try    {
                        elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
                    }
                    catch (e) {
                        elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
                    }
                    while ((node = elements.iterateNext())) {
                        returnElements.push(node);
                    }
                    return returnElements;
                };
            }
            else {
                getElementsByClassName = function (className, tag, elm) {
                    tag = tag || "*";
                    elm = elm || document;
                    var classes = className.split(" "),
                        classesToCheck = [],
                        elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
                        current,
                        returnElements = [],
                        match;
                    for(var k=0, kl=classes.length; k<kl; k+=1){
                        classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
                    }
                    for(var l=0, ll=elements.length; l<ll; l+=1){
                        current = elements[l];
                        match = false;
                        for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
                            match = classesToCheck[m].test(current.className);
                            if (!match) {
                                break;
                            }
                        }
                        if (match) {
                            returnElements.push(current);
                        }
                    }
                    return returnElements;
                };
            }
            return getElementsByClassName(className, tag, elm);
        };    
    </script>

The forum has moved

This forum is no longer in use, so you can't reply to this message - please go to Our Umbraco

Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.