0

I'm looking for a way to change the hash url automatically. (no page reload)

The reason I want it is this:

I'm using a pop login / registration form that only initially opens the login portion. You can only get to the registration portion after clicking the login. So, when the user clicks the http://website.com/#modal-login from a certain link, I'd want it to redirect to http://website.com/#register.

Currently it is directly going to the #register. Is there a way to change the hash url after user clicks on login?

1
  • 1
    No jQuery required, just plain Javascript: document.location.hash = whatever Commented Feb 22, 2014 at 3:33

1 Answer 1

3

No need to use jQuery

document.getElementById("modal-login").onClick = function () {
    window.location.hash = "register";
}

For example, try pasting this into your browser's JavaScrtipt console, then click on your question text.

document.getElementById("question").onclick = function() {
    window.location.hash = "footer";
}

If you really want to use jQuery for some reason

$('#modal-login').click(function(event) {
    event.preventDefault();
    window.location.hash = "register";
});

Edit:

Your question isn't about hash locations in general, but how this modal plugin that you're using works. The following was determined by reading the source to the plugin, found here:

http://demo.pressapps.co/plugins/wp-content/plugins/pressapps-modal-login/js/modal-login.js?ver=1.0.0 http://demo.pressapps.co/plugins/wp-content/plugins/pressapps-modal-login/js/modal.js?ver=1.0.0

Here's what you need to execute to get your desired behavior

$('.your-register-button-class').click(function(e) {
    /* We expect plugin's click handler to fire in addition to this one. */
    $(".modal-login-nav[href='#register']").click();
});

I'm assuming that the element with .your-register-button-class also has attribute data-toggle="ml-modal".

Sign up to request clarification or add additional context in comments.

4 Comments

That directs to #register, but this plugin doesn't go to the actual #register link (even though that's the link). codecanyon.net/item/…. That link is exactly what I'm using. Can you look at that and see how to open the register button instead of the login? Going directly to #register doesn't work. It seems like you would have to go to #modal-login to initialize it, then redirect to #register. (like it said, the href is pointing to #register, but like jquery tabs, it doesn't physically go there)
Updated answer specific to the plugin you're using.
Wow thanks! You went above and beyond to answer that one. I added the class "register" to the link, and added that function (with the class of "register") to the bottom of the appropriate javascript file, and it worked. That's some functionality that should be included in the plugin. Thanks!
Glad it worked. That would seem like a good feature for this plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.