如何在 .cs 中使用 Javascript 创建嵌入
注意:localhost:3197/website/js/embed/form.js'; // 给出你的 js 路径
FormBuilder(921,'MjEzNjkxMjU='); 在此方法中,第一个参数给出您的表单高度,第二个参数给出您的表单名称或 ID。有id是编码格式
StringBuilder sb = new StringBuilder();
sb.Append("<script type='text/javascript'>");
sb.Append("(function(d, t) { var s = d.createElement(t), options = {");
sb.Append("'async':true };");
sb.Append("s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'localhost:3197/website/js/embed/form.js';");
sb.Append("s.onload = s.onreadystatechange = function() {");
sb.Append("var rs = this.readyState; if (rs) if (rs != 'complete') if (rs != 'loaded') return;");
sb.Append("try { frm = new FormBuilder("+Form Height+",'"+FormId+"');frm.initialize(options);frm.display(); }");
sb.Append("catch (e) {}};");
sb.Append("var scr = d.getElementsByTagName(t)[0], par = scr.parentNode; par.insertBefore(s, scr);");
sb.Append("})(document, 'script');</script>");
txtjavascript.Value = sb.ToString(); // text box name
创建嵌入脚本后简单易用的方法将此脚本粘贴到您要在其他页面中显示的位置之后
(function(d, t) { var s = d.createElement(t), options = {'async':true }; s.src = ('https:' == d.location.protocol ?'https:// ' : 'http://') + 'localhost:3197/website/js/embed/form.js'; s.onload = s.onreadystatechange = function() {var rs = this.readyState; if (rs) if (rs != 'complete') if (rs != 'loaded') return; try { frm = new FormBuilder(921,'MjEzNjkxMjU='); frm.initialize(options); frm.display(); }catch ( e) {}}; var scr = d.getElementsByTagName(t)[0], par = scr.parentNode; par.insertBefore(s, scr);})(document, 'script');
之后在你的 js 文件中创建这样的函数并创建 iFrame 并创建查询字符串,您可以在其中从数据库中获取表单。
function FormBuilder(fHeight, formid) {
var iframe = document.createElement('iframe');
iframe.style = "height:" + fHeight + "px; width:100%; border:none";
iframe.setAttribute('allowTransparency', true);
iframe.frameBorder = "0";
iframe.scrolling = "no";
iframe.src = "http://localhost:3197/form/show-form?id="+ formid;
document.body.appendChild(iframe);
}