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
Question: Modal - how to close with jQuery? #69
Comments
Hi there, The signature to close a loaded modal is as follows.
There's a list of methods here. http://responsivebp.com/javascript/modal/#methods Hope that helps. 😄 |
Thank you :) It is really helpful! I read the modal documentation page a couple of times Btw there is a small mistake on the page: I was also trying to trigger the "hide" function without clicking any element.
Is there a way to put some code into content.php that closes the modal? Thank you! |
Thanks for that, I've updated the documentation. If the
|
Thank you. |
Are you trying to detect whether someone clicks to a certain page when the modal contains an iframe? If your page is within an iframe though there is no way to detect the current page if you have changed it from the original. Otherwise there's event's that are fired when a modal is shown. http://responsivebp.com/javascript/modal/#events You could use the same code from within that click event I demonstrated to do the same thing. |
I'm working with some php scripts that are dynamically changing the page (opened in modal). Thank you again for your reply and the marvellous work you did with the Responsive! |
Thank you! Best of luck! 😄 |
I've spent a couple of days trying to figure it out but I'm stuck. If it is not a problem please look at it (if you’ll have some spare time of course). There are 3 files: <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!-- styles -->
<link href="http://responsivebp.com/assets/css/responsive.min.css" rel="stylesheet" />
<!-- scripts -->
<script src="http://responsivebp.com/assets/js/vendor/jquery-2.1.3.min.js"></script>
<script src="http://responsivebp.com/assets/js/responsive.min.js"></script>
</head>
<body>
<a href="target.php" class="modal-trigger" data-modal>Show modal</a>
</body>
</html> Target.php <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!-- styles -->
<link href="http://responsivebp.com/assets/css/responsive.min.css" rel="stylesheet" />
<!-- scripts -->
<script src="http://responsivebp.com/assets/js/vendor/jquery-2.1.3.min.js"></script>
<script src="http://responsivebp.com/assets/js/responsive.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
//Close button function
$(".close-button").click(function(){
$(".modal-trigger").modal("hide");
});
//Transfering form data back to modal via ajax
$('#edit').submit(function(e){
e.preventDefault();
var content = $('#content').val();
var dataString = 'content=' + content;
$.ajax({
type: "POST",
url: "target.php",
data: dataString,
cache: false,
success: function(html){
$('.modal-content').html(html);
}
});
});
});
</script>
<form action="" method="post" id="edit">
<input type="text" name="content" value="content">
<input type="submit" name="submit" value="submit">
</form>
<?php
//
if(isset($_POST['content'])){
//Database update scripts
//SCRIPT USED TO CLOSE THE MODAL
include('script.php');
} ?>
<a href="" class='close-button'>close</a>
</body>
</html> Script.php <?php
echo
'<script>
$(".modal-trigger").modal("hide");
</script>';
?> tried also
and
The aim is to automatically (without additional clicking) close the modal by the script included. No idea why it doesn't work :D |
Hi!
I have one, probably simple question.
Unfortunately I can't figure it out ;)
What is the command to close the modal with jquery (called from a target page)?
The action should be pretty much the same as clicking the 'x' symbol.
And an example :)
There are to pages:
INDEX.php
CONTENT.php
Index has a link that opens content in a modal.
How to close the modal
I'll be really grateful for help!
The text was updated successfully, but these errors were encountered: