I know, there are several posts with nearly the same question, but all the mentioned "fixes" dont work for me.
but first, here is what I need: Some forms in my application have to be enabled by activating an edit mode. If the edit mode is active every button (except save and abort) and link on the page should not do what it normaly does, but it should give a message that you have to end the edit mode instead.
My script: The button to start the edit mode calls this:
function startEditMode(selector) {
var disableAction = "return false;";
jQuery("mySelectors").each(function(){
jQuery(this).bind('click', editModeOnClickHandler);
var onClickValue = "";
var onClick = jQuery(this).attr("onClick");
if ( onClick !== undefined ) onClickValue = "" + onClick;
jQuery(this).attr("onClick", disableAction + onClickValue);
});
}
To stop edit mode a method exists which reverses all of this. The used handler "editModeOnClickHandler" just shows the message and returns false; and is not important to my question.
So.. everything works fine in FF and IE8 (also in Chrome) but it does not in IE7. The onClick is simply not modified in IE7 via .attr as I read in other postings.
the solution which is posted everywhere: Use event binding instead of manipulating attributes. I wish I can use that!
Here is the reason why I cant: I tried to unbind all handlers and bind my own handler as you see in code above. But this does not prevent the inline onclick from being called. Okay you might think, dont use inline calls.. but my project is written in JSF using Primefaces and most of its code is generated dynamically. All in all I do not have the possibility to prevent inline onclicks.
Now I am stuck. I have to handle with inline onclicks which can only be prevented to be called by inserting a "return false;" in front, but this seems not to be possible with IE7.
Does anyone know a IE7 workaround to be able to manipulate the onclick attributes? And again: I can not use .bind('click'... or .click( because they are not able to stop the original inline onclick.
Thanks for all answers! Alex
edit
with your help I figured out, that in IE7 changing the inline onclick is possibile with this.onclick = ..
. The correct handling of this was alreads answered in this question: How to change onClick handler dynamically?
For my concrete problem here I found no proper solution, because I was not able to manipulate the original inline onclick values without destoying them. For that reason I changed my script, so IE7 disables all buttons and links to make sure they are no longer clickable. To be sure, not to enable too much, ill add a classname too.
disabling all not yet disabled (its called in a loop):
if (!jQuery(this).attr('disabled')) {
jQuery(this).attr('disabled', 'disabled');
jQuery(this).addClass('editmodedisabled');
}
enable my previous disabled things:
if (jQuery(this).hasClass('editmodedisabled')) {
jQuery(this).attr('disabled', '');
jQuery(this).removeClass('editmodedisabled');
}
maybe this helps anyone else