Skip to content

Commit

Permalink
fix to prevent javascript:void(0) anchors breaking placeholders in IE
Browse files Browse the repository at this point in the history
- fixes  mathiasbynens#74
- fix to prevent javascript:void(0) anchors breaking placeholders in
IE. javascript:void(0) causes beforeunload to fire off causing the
plugin to clear placeholders. We try to check to see if
javascript:void(0) is being used by calling document.activeElement
  • Loading branch information
amerikan committed Nov 10, 2015
1 parent b4545b8 commit 891fa63
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions jquery.placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,21 @@

// Clear placeholder values upon page reload
$(window).bind('beforeunload.placeholder', function() {
$('.'+settings.customClass).each(function() {
this.value = '';
});

var clearPlaceholders = true;

try {
// Prevent IE javascript:void(0) anchors from causing cleared values
if (document.activeElement.toString() === 'javascript:void(0)') {
clearPlaceholders = false;
}
} catch (exception) { }

if (clearPlaceholders) {
$('.'+settings.customClass).each(function() {
this.value = '';
});
}
});
}

Expand Down

0 comments on commit 891fa63

Please sign in to comment.