Recently had to use mailto:
in href and callback function on onclick
event at the same time to let google email (= gmail) understand and display the recipient’s email address.
Old code
<a id="webdesigncolors-email"
href="mailto:{{webDesignColors.email}}"
target="_blank"
onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to={{webDesignColors.email}}, '_blank');">Email me</a>
The problem
Inspect the page and look at your console for error:
Interpolations for HTML DOM event attributes are disallowed. Please use the ng- versions (such as ng-click instead of onclick) instead.
- Can’t get email address into gmail’s compose feature
- Inline ‘onclick’ attracts XSS vulnerability. Anyway inline events are bad!
- Interpolations for HTML DOM event attributes are disallowed in AngularJS
- Is ‘target’ attribute really needed?
- Code has complexity. Can we make it simpler and shorter?
- If we remove
mailto
from href then local email client (say Outlook) don’t opened - If we remove onclick event gmail task can’t be completed
Solution
- Keep the markup simple and shorter
- Keep
mailto
inhref
but remove inlineonclick
- Trigger
click
event on element ID in Angular Controller
<a href="mailto:{{webDesignColors.email}}" id="webdesigncolors-email">Email me</a>
angular
.module('WDC')
.controller('EmailController', function (Users, $scope, $routeParams, $route) {
$scope.webDesignColors.email = 'email1@gmail.com';
document.getElementById('webdesigncolors-email').onclick = function (element) {
window.open('https://mail.google.com/mail/?view=cm&tf=1&to=' + element.target.href.split(':')[1], '_blank');
};
});
You might also like:
AngularJS learning and examples:
- Conflict between ng-attr and SVG elements
- AngularJS advanced accordion
- Scope variable over multiple queries in AngularJS
- Advanced search in AngularJS
- Basic search in AngularJS
- AngularJS in 20 minutes
- Angular column filter for Bootstrap
- AngularJS ‘mouseleave’ event : error and solution
jQuery plugins:
- jqExtension – jQuery file type validation plugin
- jQuery validation for file type extension
- jQuery validationEngine: Extended jQuery form validations
- jQuery Ad Gallery – Extended Photo Gallery Slideshow
- Simple and easy Cookie based jQuery tabs
- Simple jQuery Single Level Drop Down Menu
Leave a Reply