-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Consider switching to javascript:void(0) for hrefs #916
Comments
+1 to this one, didn't notice the #'s before but I've been bit by this before. |
I thought we weren't planning to support IE < 9? |
@cgiffard Even IE9 doesn't support pushState 😢 |
Is this issue mitigated by jashkenas/backbone#2766? |
Whether or not it is, I would still vote against them because they force the # appended on the url which I find offends my delicate southern sensibilities. |
How about a JavaScript solution? I'm going to propose a function like this for intercepting URLs in order to make pushstate work with ordinary links. hijackLinks: function(ev) {
var $target = $(ev.currentTarget);
// Get the absolute anchor href.
var href = { prop: $target.prop("href"), attr: $target.attr("href") };
// Get the absolute root.
var root = location.protocol + "//" + location.host + urls.root;
// Ensure the root is part of the anchor href, meaning it's relative.
if (href.prop.slice(0, root.length) === root) {
// Stop the default event to ensure the link will not cause a page
// refresh.
ev.preventDefault();
// `Backbone.history.navigate` is sufficient for all Routers and will
// trigger the correct events. The Router's internal `navigate` method
// calls this anyways. The fragment is sliced from the root.
Backbone.history.navigate(href.attr, true);
}
}
$(document.body).on("click", "a[href]:not([data-bypass])", hijackLinks); We could easily add a case to ignore |
Couple of thoughts: First - There is a 7+ year old ticket about this on bugzilla - https://bugzilla.mozilla.org/show_bug.cgi?id=349259 - indicating they have zero intention of changing it. The long and short of the issue is that it's impossible to properly set the height of a Second - and I'm not sure how relevant this is to this particular issue - but without an |
I think what @jgable is getting at is using |
Yeah, the |
I would suggest setting the href's to a useful path and remove it where it is not applicable.
So, let's get rid of the #'s! ...and yes, @JohnONolan the "Don't touch my UI elements"-attitude in Firefox is really annoying, I remember when they did it hardcore in Safari too... |
@bastilian brings up a good point: if we are going to support Ghost without JavaScript (as in #1205), then links are going to need to point to a real server address (which can then be caught and redirected to Backbone as necessary when JavaScript is enabled). |
Don't use javascript:void(0); I have <a href="javascript:somefunction()"> what ... ? Whatever the rest of your question, this is generally a very bad idea. <a href="javascript:'<h1>' + document.lastModified + '</h1>'">lastModified</a>
will result in replacing the current document with the value
returned from
When the expression used evaluates to an It is also possible for IE to be configured such that it supports The Instead, use |
In the interest of saving a few bites - if it is decided to use the |
Am I right in thinking Ember solves this for us and that this can be closed purely as a fact of switching to Ember? |
It looks like the |
I've noticed that in Ember if you have So at the very least we probably shouldn't use |
Sounds like we need a global solution / convention for this then as part of the Ember project |
Any anchor elements that navigate to a route should naturally use the Ember All other elements that just have JavaScript actions attached shouldn't be anchor elements IMO. It's not what anchor elements are intended to be used for. |
So - use {{#link-to}} or a button is the solution, I've assigned this to @PaulAdamDavis as I know he was talking about moving towards using more buttons and that mostly requires ghost-ui work. |
Closed by #3277 |
I know this can be kind of contentious / personal taste issue, but the #'s in our urls can potentially cause us problems down the road with backbones routing on browsers like IE9 that don't support pushState.
We should consider switching to javascript:void(0) to avoid changing the url when clicking about. Or, we could start using button's where semantically they would be more correct.
The text was updated successfully, but these errors were encountered: