2013-12-22 37 views
0

我正試圖創建一個非常基本的書籤。通過URL將數據傳遞給表單

我的表單存在於頁面上,例如mysite.com/posts/,在引導模式框中。

<div class="post-window"> 
    <div class="window-left"> 
     <textarea name="title_image" class="form-control" rows="3" placeholder="Post title"></textarea> 
    <input name="postimage" class="form-control" placeholder="Post image URL" /> 
    </div> 
</div> 

<div class="modal-bottom"> 
    <div class="upload"> 
    <input type="hidden" name="letsbingo" value="1" /> 
     <button class="btn-block">Post Selfie</button> 
    </div> 
</div> 

1-以下是bookmarklet代碼,它工作正常。

javascript: var selfiesite = 'SelfieNow', 
    selfiesiteurl = 'http://my.com/post/'; 
(function() { 
    if (window.selfiesiteit !== undefined) { 
     selfiesiteit(); 
    } else { 
     document.body.appendChild(document.createElement('script')).src = 'http://my.com/assets/js/postit.js'; 
    } 
})(); 

2-以上JavaScript是正是我想要的如下所示

http://my.com/post/?postimage=%3A%2F%2Fexample.com%2Fwp-content%2Fuploads%2F2013%2F12%2FGripster-Wrap-Mini-For-The-Ipad-Mini-3-690x460.jpg&title_image=Example%20-%20Men%27s%20Gear%2C%20Lifestyle%20and%20Trends 

3-現在我my.com/post/,則爲一塊Javascript角的觸發對窗口模式對話框結果加載。

jQuery(window).load(function ($) { 
    jQuery('#postModal').modal('show'); 
}); 

小書籤正在工作,模式框在窗口加載時打開。但數據並未傳遞到形成。表單在模式框中打開,url已更改,但表單顯示爲空。我不知道什麼是錯的。無論是模式框打開(在窗口加載)錯誤的方式或書籤創建的url不適合這種形式。請引導我一點。

回答

0

嘗試綁定您的JS function當模式顯示。像這樣:

$('#postModal').on('show', function() { 
    var selfiesite = 'SelfieNow', 
    selfiesiteurl = 'http://my.com/post/'; 
    if (window.selfiesiteit !== undefined) { 
     selfiesiteit(); 
    } else { 
     document.body.appendChild(document.createElement('script')).src = 'http://my.com/assets/js/postit.js'; 
    } 

});