I am facing an issue with the Locker Service. I have a simple piece of code. I have attached the code here. The issue is that if the Locker Service is disabled, I am able to open a link in new tab using "target" attribute the element output is as shown in the screenshot. Whereas, if it is enabled, I am unable to open a link in new tab using "target" attribute. I have attached both screenshots as well as the code. Winter 17 - Salesforce
DemoTestApp.app
<aura:application >
<c:testJqueryComponent />
</aura:application>
DemoTest.cmp
<aura:component >
<ltng:require scripts="{!join(',',
$Resource.jQuery + '/jquery/lightning/js/jquery-2.2.4.min.js',
$Resource.jQuery + '/jquery/lightning/js/jquery-migrate-1.3.0.min.js')}"
afterScriptsLoaded='{!c.doResult}'/>
<div id="divTest"></div>
<button id="btnView" >Read TR</button>
</aura:component>
DemoTestController.js
({
doResult : function(component, event, helper) {
$("#divTest").html('<table><tr role="row">'
+'<td role="cell" aria-describedby="1">value 1</td>'
+'<td role="cell" aria-describedby="2"><a target="_blank" href="www.google.com">google</a></td>'
+'</tr></table>');
}
)}
html()
API sets the string you pass it to.innerHtml
and Locker will sanitize anything passed to.innerHtml
with a library called DOMPurify. DOMPurify automatically strips thetarget
attribute from anchor tags.