From 891fa637a8b27d00b394f842a596a47beb12f335 Mon Sep 17 00:00:00 2001 From: Erik Montes Date: Tue, 10 Nov 2015 13:06:57 -0800 Subject: [PATCH] fix to prevent javascript:void(0) anchors breaking placeholders in IE - fixes #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 --- jquery.placeholder.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/jquery.placeholder.js b/jquery.placeholder.js index 1c43019..f65976c 100644 --- a/jquery.placeholder.js +++ b/jquery.placeholder.js @@ -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 = ''; + }); + } }); }