<a class="modal" id="fblogin_pop" rel="{size: {x: 450, y: 400}, ajaxOptions: {method: \'get\'}}" href="#fblogin_btn">fblogin</a>
this is my link tag and click on that open popup for facebook login. now i want to trigger this event on pageload if user is not login for this i make this code. but those popup not open.
jQuery(window).load(function() {
jQuery('#fblogin_pop').click();
});
please help me if any one also faced this issue and have idea to short out.
Thanks.
答案 0 :(得分:0)
你的Jquery应该是:
$(document).ready(function(){
$('#fblogin_pop').click();
});
或
$(document).ready(function(){
$('#fblogin_btn').modal('show');
});
或
$(document).ready(function(){
document.getElementById("fblogin_pop").click();
});
其中一个应该可以正常工作。并且您给锚点的href和ID看起来像互换了。交叉检查
答案 1 :(得分:0)
要在window.load()上打开弹出模式,只需使用以下jquery代码。
$(window).on('load',function(){
$('#yourModalId').modal('show');
});
#yourModalId
指的是你的模态。
在您的localhost上查看此演示 -
$(window).on('load', function() {
$('#fblogin_pop').modal('show'); // Simple way to open modal on window.load();
/* Alternative way using trigger click function
$('a').trigger('click');
*/
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<a href="#" data-toggle="modal" data-target="#fblogin_pop" rel="{size: {x: 450, y: 400}, ajaxOptions: {method: \'get\'}}">FB Login</a>
<div id="fblogin_pop" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
希望,这可能对你有用。 :)
答案 2 :(得分:0)
尝试:
$('#fblogin_pop').trigger( "click" );