How to fix console error " Refused to run the JavaScript URL..."

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • telecastg
    Active Community Member
    • Jun 2018
    • 907

    How to fix console error " Refused to run the JavaScript URL..."

    If you encounter the console log error: " Refused to run the JavaScript URL because it violates the following Content Security Policy directive: "default-src 'self" it is very likely caused because modern browser security policy prohibits calling javascript code directly from html.

    In my case, I had an <a> element that was being used as a button to call a javascript function (old coding habit) and the browser kept on throwing the error every time I clicked on the <a> element, so I substituted the <a> element with a transparent borderless <button> element and changed the event catching function in the template's view as sown below.

    BEFORE:

    custom/modules/data-visualization/res/templates/instruments/progress-cards.tpl
    Code:
    <a href="javascript:" class="card-link" data-criteriavalue="{{{categoryValue}}}">
        <span class="card-icon {{categoryIcon}} icon-{{categoryClass}} float-right"></span>                                    
     </a>​
    client/custom/modules/data-visualization/src/views/dashlets/instruments/progress-cards.js
    Code:
    events: {        
            'click a.card-link': function(e) {
                // run my code in response to the clicking event  
            }​
    }
    AFTER

    custom/modules/data-visualization/res/templates/instruments/progress-cards.tpl
    Code:
    <button class="card-link" data-criteriavalue="{{{categoryValue}}}" style="background-color:transparent;outline:none;border:none;">
        <span class="card-icon {{categoryIcon}} icon-{{categoryClass}} float-right"></span>                                    
    </button>​
    client/custom/modules/data-visualization/src/views/dashlets/instruments/progress-cards.js
    Code:
    events: {        
            'click button.card-link': function(e) {
                // run my code    
            }​
    }
  • yuri
    Member
    • Mar 2014
    • 8440

    #2
    HTML Code:
    <a role="button">Action</a>
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    Working...