Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript:void(0) in <a> is breaking the placeholder #74

Closed
alexandrejobin opened this issue Apr 27, 2012 · 15 comments
Closed

javascript:void(0) in <a> is breaking the placeholder #74

alexandrejobin opened this issue Apr 27, 2012 · 15 comments
Labels

Comments

@alexandrejobin
Copy link

When you click on a link that use javascript:void(0) as the href, the placeholder disapear in IE7 & IE8 (maybe others too)

<a href="javascript:void(0)" onClick="doSomething()">
@rafalbromirski
Copy link

Same situation here. I've found only one solution:

<a href="#">...</a>
$("a").on("click", function(e)
{
   e.preventDefault();
   doSomething();
});

@Sangdol
Copy link

Sangdol commented Jul 13, 2012

Why is this issue happens? Is it unfixable? I prefer to use javascript:void(0) because of this reason.

@tysonnero
Copy link

I'm seeing the same thing.

@dashdots
Copy link

I'v got same problem: focus the textbox and hit twice ESC or click the anchor that href prop is set with 'javascript:void(0);', that will clear all of the placeholder.

@roeycohen
Copy link

hi, anyone succeeded in working this out??
this also happens in ie 9 and 10!

@youryss
Copy link

youryss commented Sep 8, 2014

Its 2014 and the issue still happing! :/

@amerikan
Copy link
Collaborator

Why not just use a <button> instead? If you want to make it look like an anchor, just style it that way. Something like:

.button-link {
    background: transparent;
    border: 0;
    color: blue;
    padding: 5px;
    text-decoration: underline;
}
<button type="button" onClick="doSomething()" class="button-link">test</button>

😃

Edit: also there's a PR #170 that claims to solve this. I haven't tried it myself, but maybe you guys can try it out and see if it solves your issue? If so, let me know.

@antoinebrault
Copy link

Maybe something along the lines of :

var last_clicked;
$("body").on('click', 'a', function() {
    last_clicked = this;
});

// Clear placeholder values upon page reload
$(window).bind('beforeunload.placeholder', function(e) {
    if (last_clicked && last_clicked.href !== 'javascript:void(0)') {
        $('.'+settings.customClass).each(function() {
            this.value = '';
        });
    }
});

might work...

@rRudeBoy
Copy link

I can confirm this behavior is still occurring in IE9, Aug 2015. Regarding the link Sangdol posted giving a positive reason for using javascript:void(0), deeper in that answer it's suggested that best practice is to simply not have an href attribute, which I found to be a workable solution.

@RASMiranda
Copy link

Still happening on IE9.
Can confirm that @Paranoida simple workaround prevents the behavior.

@amerikan amerikan added the bug label Nov 10, 2015
@amerikan
Copy link
Collaborator

Using <a href="javascript:void(0);" >Click</a> in IE will trigger a beforeunload event. Currently the plugin will clear input values for beforeunload events. So I think @antoinebrault is in the right track.

@amerikan amerikan reopened this Nov 10, 2015
@amerikan
Copy link
Collaborator

I've fixed this in this commit: 891fa63

Full file is here:
https://github.com/mathiasbynens/jquery-placeholder/blob/gh-pages/jquery.placeholder.js

I tested it myself and with this, it is fixed. Can any of you test the fix to confirm it?

@RASMiranda
Copy link

Not working, some behavior happening with v2.2.0

@amerikan
Copy link
Collaborator

@RASMiranda the fix is not in v2.2.0 yet. Try including this https://github.com/mathiasbynens/jquery-placeholder/blob/gh-pages/jquery.placeholder.js in your script. I'm waiting to fully confirm before releasing the fix in a future release.

@RASMiranda
Copy link

@amerikan Ha didn't realised it was not realeased, tried with https://github.com/mathiasbynens/jquery-placeholder/blob/gh-pages/jquery.placeholder.js same behavior :-/
But maybe my case is not the best. It has some other plugins that might be messing up and some other stuff that I don't know off.
I'll have to live with the workaround for now, don't have much time to test it further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests