I'm trying to make a Magnific Popup automatically appear on page load.
I have it so it works when I click a button (which narrows down some possible errors), but I still can't get it to appear on load. I've tried this and this, but neither seems to be working.
<script>
$('.open-popup-link').magnificPopup({
type:'inline',
midClick: true // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href.
});
$.magnificPopup.open({
type: 'inline'
});
</script>
Can anyone help me get this straightened out? Ideally it would open automatically and when the button was clicked.
ADDITIONAL INFO
Here's the html/erb for the button that works:
<p><a href="#test-popup" class="open-popup-link btn btn-ghost hvr-grow" style="margin-top: 40px">Quick Man Check</a></p>
And here's the content:
<div id="test-popup" class="white-popup mfp-hide">
<div class="">
<h1>Answer the following question to gain entry:</h1>
<% @random_partial = 'man_tests/test' + rand(0).round.to_s %>
<%= render partial: @random_partial %>
</div> <!-- hover-well -->
</div> <!-- white-popup mfp-hide -->
Clarification: The popup has a submit button for form data, which causes problems with it appearing once but only once.
Update: As suggested, both this:
$.magnificPopup.open({
items: {
src: '#test-popup',
type: 'inline'
}
});
And this:
$('.open-popup-link').magnificPopup('open');
Make it open on load, but it then continues doing so ad nauseum, never allowing the index page to be viewed.