I'm using a plugin called Reveal, and trying to fire it based on whether a variable is present in the URL (i.e. www.mysite.com?status=new). I have tested the GET status code (works fine, echoed it) and also set up reveal to work when a button is pressed. Both work flawlessly. However, the goal is to fire the event if the status == new. This is my code:
<?
if($status == 'new'){
echo '<script type="text/javascript">$(\'#myModal\').reveal();
</script>';
}
?>
Doesn't work :/ Any help? I've tried many combinations with this and nothing seems to be working. My code is placed near the bottom of the page (in the body section), not sure if that matters..
EDIT: Also tried this (didn't work):
<?
if($status == 'new'){
echo '<script type="text/javascript">
开发者_开发技巧 $(document).ready(function() {
e.preventDefault();
$(\'#myModal\').reveal();
});
</script>';
}
?>
Zach
Try this:
echo '
<script type="text/javascript">
$(document).ready(function(){
$(\'#myModal\').reveal();
});
</script>';
as m90 already suggested, probably a good idea to load up the DOM before you execute the script. And you can place it anywhere, usually I place it in the head though, but it's all good.
Be aware that this kind of inline JS will be executed immediately by the browser, so it might be that the element you are trying to reveal isn't ready to be revealed yet (therefore nothing happens). Usually you will fix this by calling your scripts on $(document).ready()
. See this article on the jQuery website
just wanted to put here a little bit different approach:
// Example URL:
// test.php?status=Message
var $_GET = <?php echo json_encode( $_GET ); ?>;
// alert( $_GET['status'] );
// console.log($_GET);
精彩评论