2013-01-05 166 views
1

我有代碼BU阿賈克斯這樣的:開彈出對話框打開時

$("document").ready(function(){ 

$(".open_popup").colorbox({width:"580px", inline:true, href:"#subscribe_popup"}); 

    }); 

這是彈出框,我需要在打開的頁面中打開該彈出窗口,打開這個彈出我用這個代碼

<a href="#" class="open_popup">Click here to open the popup</a> 

如何打開彈出的onload標籤在身上。

+0

您是否希望有一個彈出的頁面加載無論用戶交互時,或者當'了'標籤被點擊時? – nerdarama

+0

當我點擊一個打開,但我需要打開時,加載頁面 –

回答

1

如果要加載內嵌的內容(#subscribe_popup),你應該使用html屬性,而不是href

Colorbox documentation

$.colorbox({html:$('#subscribe_popup')}) 

至於對方的回答表明,使用它裏面$(window).load()

$(window).load(function(){ 
    $.colorbox({html:$('#subscribe_popup')}) 
}); 
+0

這個怎麼用? –

+0

答覆已更新。 – Salman

3

一種方法是簡單地觸發鏈接上的點擊事件。

$(window).load(function(){ 
    $(".open_popup").trigger("click"); 
}); 
+0

不,我需要打開彈出框時加載頁面不要點擊 –

+0

是的,但是當我理解你的權利,彈出處理程序是點擊事件a。所以當你模擬點擊a時,彈出窗口打開。 – lukasgeiter

-1

嘗試:

function pop() 
{ 
    $("document").ready(function(){ 

     // load the overlay 

     if (document.cookie.indexOf('visited=true') == -1) { 
      var fifteenDays = 0; 
      var expires = new Date((new Date()).valueOf() + fifteenDays); 
      document.cookie = "visited=true;expires=" + expires.toUTCString(); 
      $.colorbox({width:"580px", inline:true, href:"#subscribe_popup"}); 
     } 

     $(".open_popup").colorbox({width:"580px", inline:true, href:"#subscribe_popup"}); 

}); 
} 

在身體標記:

<body onload="javascript: pop()"> 
-1
 <!--Jquery bootstrap Library--> 
    <!--bootstrap css file--> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css"> 

     <!--Window Control Code (You Are Perform)--> 
     <script> 
      $(window).load(function() 
      { 
       $('#myModal').modal('show'); 
      }); 
     </script> 
     <!--Window Control Code (You Are Perform)--> 
     <!--Pop Style CSS--> 
     <style> 
     .popupp h4{ 
     font-size:1.6em; 
     color:#0084C4; 
     font-family:"Times New Roman", Times, serif; 
     font-weight:bold; 
     padding:0em 0em 0.5em 0em; 
     text-align:center; 
     margin:0px; 
     } 
     .popupp h4 span{ 
     font-size:1.2em !important; 
     } 
     .queryform input[type=text],textarea,input[type=email],input[type=number]{border: 1px solid #CEC7C7; margin-bottom:1em; outline-color: #FF5B36; width:100%; font-size: 0.9em; padding:1em; -webkit-appearance: none; color: #B1B1B1;} 
     .queryform input[type=submit]{border: 1px solid #CEC7C7; margin-bottom:1em; outline-color: #FF5B36; width:100%; font-size:1em; background:#000; padding:1em; -webkit-appearance: none; color: #fff;} 
      .queryform textarea{ height:100px;} 
      .queryform 
      { 
       padding: 0.5em 5em; 
      } 

      .close { 
      font-size:4em; 
      } 
      .modal-header .close { 
       margin-top: -31px; 
      } 
     </style> 
     <!--Pop Style CSS--> 
     <!--Define Pop Up--> 
      <!-- Modal --> 
      <div class="modal fade" id="myModal" role="dialog"> 
      <div class="modal-dialog">  
       <!-- Define Pop Up content--> 
       <div class="modal-content"> 
       <div class="modal-header popupp"> 
       <button type="button" class="close" data-dismiss="modal">&times;</button> 
        <h4 class="modal-title"><span> Need Instant Services </span> ??? </h4> 
        <div class="queryform"> 
        <form method="post" action="contact-post.php"> 
         <input type="text" name="name" placeholder="Enter Your Name" required> 
         <br />     
         <input type="number" name="mobile" oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);" maxlength = "10" minlength = "10" placeholder="Enter Your Mobile Number" required> 
         <br />     
         <input type="email" name="email" placeholder="Enter Your Email Address" required> 
         <br /> 
         <textarea name="msg" placeholder="Enter Your Requirment" required></textarea> 
         <br />  
         <p align="center"><input type="submit" value="Enquiry" name="enquiry_home"></p> 
        </form> 
        </div> 
       </div> 
       <div class="modal-footer"> 
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
       </div> 
       </div>  
      </div> 
      </div> 
+1

此代碼正在工作?? –

+0

儘管此代碼可能會回答這個問題,但提供有關如何解決問題和/或爲何解決問題的其他上下文會提高答案的長期價值。 – DaniEll

+0

附加上下文僅供參考,以便於理解解決方案 –