0

I have a pop-up link that detects if its a external link. The pop-up is able to detect if there is a external link correctly.

The website is using Mura CMS which users have used a feature in Mura to create links within Mura (click here). This is a problem do to users creating Mura links that have external links and the logic in play is unable to detect whether the link is internal or external.

The following is the logic being used to detect external links:

$("a:not('.frontEndToolsModal')").on('click', function(e){
    e.preventDefault();
    var url = $(this).attr('href'),
        host = location.host;

    if (url.indexOf(host) > -1 || url.indexOf('http','https') == -1){
        /* If we find the host name within the URL,
           OR if we do not find http or https, 
           meaning it is a relative internal link.

           The following statements is to not interefere with Mura CMS front end tools
        */

        if(url.indexOf('/admin/?muraAction=cArch.list') == 0){
            var newTab = window.open(url, '_blank');
            newTab.focus();
        }
        else if(url.indexOf('/admin/?muraAction') == 0){
            //do nothing
        }else{
            window.location.href = url;
        }
    }else {

        var m = modal.open({content: "POP UP MESSAGE"});

        if(m == true) {
            return m;
        } 
    }
});

My question is: How can I detect whether the Mura link created contains a internal or external link?

INSGUEST
  • 3
  • 6
  • Do the links that the users create within Mura have a CSS class of 'frontEndToolsModal'? The jQuery code that you have posted should bind to all links _except_ those with a CSS class of 'frontEndToolsModal'. – Miguel-F Mar 05 '19 at 12:50
  • @Miguel-F: For your quesiton, no. The CSS class you mentioned involves the Mura tools that a user has access to when they are able to login in to modify pages, add pages, etc. – INSGUEST Mar 05 '19 at 16:02
  • So in that case, if that same jQuery is running on the page it should work like the others. Can you provide an example of the HTML and link that is generated and does not work with the jQuery code? – Miguel-F Mar 05 '19 at 16:31
  • @Miguel-F: The problem I am encountering is Mura has a feature to create links and it is recognize as internal links. Not sure why, but the users have pasted internal links in these Links. And the way to grab the URL value is through m.content('body') which I do not know how to grab the value if the pop up and the modal is in my js file. – INSGUEST Mar 05 '19 at 18:11
  • Not sure I follow. Could you post code examples of what you are talking about? – Miguel-F Mar 05 '19 at 18:32
  • What I mean is, the code `m.content('body')` is a ColdFusion server variable/method. The JavaScript/jQuery is client code. So that jQuery code will not process until after the `m.content('body')` has already been generated into HTML and sent to the user. At that point it seems like the jQuery code should bind to all links (except those with the CSS class mentioned. Right? – Miguel-F Mar 05 '19 at 18:45
  • @Miguel-F: In Mura, you are able to create links ([link](https://docs.getmura.com/v7/content-managers/basic-content/content-types/link/)) in the "Create Content" option. This link is simply a url link. Users have posted external link within this url. – INSGUEST Mar 05 '19 at 18:50
  • @Miguel-F: Yes, you are right and it does. I am able to detect, for the most part, internal and external links. The problem is I am not sure how to grab the url destination at the time the page loads. I was thinking of going to my header.cfm file and try to see if I can see the url's within the page and then modify my js file to accept the url being passed – INSGUEST Mar 05 '19 at 18:53
  • Okay, so you are wanting to do something with these links on page load - not when they are clicked? If so, then you may need to do something like loop over all of the links in the page instead of binding to the click event. Use something like `$('a').each(function(){ // do stuff here });` on page load. – Miguel-F Mar 05 '19 at 21:14
  • @Miguel-F: Right and that is a option of what I did. But, the problem is the Mura Link Content contains a external link. So, the Mura Link Content is viewed as a internal link although it holds a external link and I have no way to grab the Mura url value – INSGUEST Mar 05 '19 at 22:36
  • Please add an example of the generated HTML link content that you are describing. Edit your question and add the code there so we can see what you are talking about. – Miguel-F Mar 06 '19 at 12:46

0 Answers0