vodkabears / Remodal

No longer actively maintained.
http://vodkabears.github.io/remodal/
MIT License
2.75k stars 771 forks source link

hashTracking and javascript initiated modal #189

Closed katag9k closed 8 years ago

katag9k commented 8 years ago

using JavaScript to open the modal, I don't want the hash to appear in the url as upon reload the dynamically populated modal comes up blank.

using var options = {hashTracking: false}; with modal.open(); but url still appears with http://mydomian.com/#modal

Can the hash be omitted from the url?

codeclown commented 8 years ago

Just to be clear, you're passing the options to element.remodal(options)?

If that's the case, a fiddle would help.

katag9k commented 8 years ago

Fiddle won't show the issue because you cannot reload it.

Here is a test page: http://test.kaygee.ca/modal.html

Click on the link, it populates the modal text and opens the modal. Reload the page, the modal opens and is blank. The issue: on reload I don't want the modal to launch automatically. I thought by turning hashTracking: false the hashtag wouldn't appear in the URL bar, thus the modal would not open on browser refresh.

tsyber1an commented 8 years ago

Having the same issue.

codeclown commented 8 years ago

What happens if you move the remodal initialization out of the click-event?

var options = {hashTracking: false};
var modal = $( '[data-remodal-id=modal]' ).remodal( options );

$('#go-modal').click(function() {
    $('.remodal p').html('Dynamic text inserted via JavaScript');
    modal.open();
});

That should be executed after DOM is fully loaded, obviously.

I think what's happening is that Remodal sees the hash, and since the element in question hasn't been explicitly initialized with hashTracking: false yet (you do that only after the link is clicked), it will open the modal.

katag9k commented 8 years ago

You are right, moving it out of the click event works:

http://test.kaygee.ca/modal01.html

Thanks!