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

How to open modal on page load? #46

Closed
ScotsScripts opened this issue Jun 27, 2013 · 9 comments
Closed

How to open modal on page load? #46

ScotsScripts opened this issue Jun 27, 2013 · 9 comments
Labels

Comments

@ScotsScripts
Copy link

Is there a way to open the model on page load instead of by clicking a link?

(this isn't an "issue" but I'm not sure how to post a question, sorry if I broke protocol)

@4nduril
Copy link
Contributor

4nduril commented Jun 27, 2013

You can load it by opening a url with fragment identifier. I.e. somesite.com/#modal1 for example.

@ScotsScripts
Copy link
Author

That makes sense. I was thinking more along the lines of arbitrarily opening it up on a page load regardless of which link they click on. For example, have the modal open on the 4th page load by a site visitor. Is there a way to set that #modal1 fragment identifie using javascript when the page loads? Thanks for the help, I appreciate it.

@4nduril
Copy link
Contributor

4nduril commented Jun 27, 2013

You could do something like location.hash = "modal1";. Wrap it in any (callback) function you want to.

@ScotsScripts
Copy link
Author

I was able to figure out how to make it work with your suggestion. This is going to help with something I'm working on, really appreciate the tip, thanks!

@drublic drublic closed this as completed Jun 27, 2013
@ScotsScripts
Copy link
Author

I just ran into an issue with this. In firefox when I change the hash, the modal doesn't automatically pop up. The other browsers work as expected. Perhaps I'm not doing it right. In the head I have this (sm is the id of the modal):

<script type="text/javascript">window.location.hash = "sm";</script> </script> <script src="js/modal.js"></script>

It's a very simple setup but even though #sm is being added to the URL, the modal doesn't automatically pop up. It will come up if I reload the URL with the #sm on it. Any ideas?

@ScotsScripts
Copy link
Author

Head example didn't come through, I'll try indenting it.

<script type="text/javascript">window.location.hash = "sm";</script>
<link rel="stylesheet" href="css/modal.css"></script>
<script src="js/modal.js"></script>

@anselmh
Copy link
Contributor

anselmh commented Jul 2, 2013

Thanks for the additional details. As I am able to confirm this, I now reopen the issue. A bugfix is coming soon! For the time being you can fix this by extending the :target selectors by:

&:target,
&.is-active {
    …
}

As the .is-active class is set by the js this will then trigger your modal on load.

@anselmh anselmh reopened this Jul 2, 2013
@ScotsScripts
Copy link
Author

That worked! I went into the css file and found every instance of :target and basic went from this:

.semantic-content:target {
display: block\9;
 }

to this:

.semantic-content:target, .semantic-content.is-active {
display: block\9;
 }

Thanks a lot for the help, it's very much appreciated.

anselmh added a commit that referenced this issue Jul 2, 2013
This targets #46. Please close the issue
if that is a complete valid fix.
anselmh added a commit that referenced this issue Jul 12, 2013
anselmh added a commit that referenced this issue Jul 12, 2013
@drublic drublic closed this as completed Jul 12, 2013
@drublic
Copy link
Owner

drublic commented Jul 12, 2013

The fix landed. Thanks :)

anselmh added a commit that referenced this issue Oct 7, 2013
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

4 participants