在iframe中引用字段输入

时间:2014-10-31 17:17:11

标签: javascript iframe wufoo

目前我的网页:http://www.sagu.edu/spec-home

特别是页脚形式。

我目前正在尝试访问电子邮件字段Field121。

目前我有这个:

var trackcmp_email = wufooFormm73jde715tzew1.document.getElementById("form227").Field121.value;

但它显示错误wufooFormm73jde715t

<div class="custom">
  <div id="wufoo-m73jde715tzew1">
    <iframe id="wufooFormm73jde715tzew1" class="wufoo-form-container" height="383" allowtransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none" src="https://sagu.wufoo.com/embed/m73jde715tzew1/def/embedKey=m73jde715tzew1327047&amp;entsource=&amp;referrer=">&lt;a href="https://sagu.wufoo.com/forms/m73jde715tzew1/" title="html form"&gt;Fill out my Wufoo form!&lt;/a&gt;</iframe>
  </div>
  <script type="text/javascript">
    var m73jde715tzew1;
    (function(d, t) {
      var s = d.createElement(t),
        options = {
          'userName': 'sagu',
          'formHash': 'm73jde715tzew1',
          'autoResize': true,
          'height': '1022',
          'async': true,
          'host': 'wufoo.com',
          'header': 'show',
          'ssl': true
        };
      s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'www.wufoo.com/scripts/embed/form.js';
      s.onload = s.onreadystatechange = function() {
        var rs = this.readyState;
        if (rs)
          if (rs != 'complete')
            if (rs != 'loaded') return;
        try {
          m73jde715tzew1 = new WufooForm();
          m73jde715tzew1.initialize(options);
          m73jde715tzew1.display();
        } catch (e) {}
      };
      var scr = d.getElementsByTagName(t)[0],
        par = scr.parentNode;
      par.insertBefore(s, scr);
    })(document, 'script');
  </script>
  <script type="text/javascript">
    var trackcmp_email = wufooFormm73jde715tzew1.document.getElementById("form227").Field121.value;
    alert(trackcmp_email);
    var trackcmp = document.createElement("script");
    trackcmp.async = true;
    trackcmp.type = 'text/javascript';
    trackcmp.src = '//trackcmp.net/visit?actid=609412436&e=' + encodeURIComponent(trackcmp_email) + '&r=' + encodeURIComponent(document.referrer) + '&u=' + encodeURIComponent(window.location.href);
    var trackcmp_s = document.getElementsByTagName("script");
    if (trackcmp_s.length) {
      trackcmp_s[0].parentNode.appendChild(trackcmp);
    } else {
      var trackcmp_h = document.getElementsByTagName("head");
      trackcmp_h.length && trackcmp_h[0].appendChild(trackcmp);
    }
  </script>
</div>

zew1 is not defined.

以下是我要访问的iframe

<div id="wufoo-m73jde715tzew1"><iframe id="wufooFormm73jde715tzew1" class="wufoo-form-container" height="383" allowtransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none" src="https://sagu.wufoo.com/embed/m73jde715tzew1/def/embedKey=m73jde715tzew1327047&amp;entsource=&amp;referrer=">&lt;a href="https://sagu.wufoo.com/forms/m73jde715tzew1/" title="html form"&gt;Fill out my Wufoo form!&lt;/a&gt;</iframe></div>

我正在尝试将wufoo iframe中的电子邮件字段用于此处的有效广告系列:

<script type="text/javascript">


var trackcmp_email = wufooFormm73jde715tzew1.document.getElementById("form227").Field121.value;
alert(trackcmp_email);
var trackcmp = document.createElement("script");
trackcmp.async = true;
trackcmp.type = 'text/javascript';
trackcmp.src = '//trackcmp.net/visit?actid=609412436&e='+encodeURIComponent(trackcmp_email)+'&r='+encodeURIComponent(document.referrer)+'&u='+encodeURIComponent(window.location.href);
var trackcmp_s = document.getElementsByTagName("script");
if (trackcmp_s.length) {
    trackcmp_s[0].parentNode.appendChild(trackcmp);
} else {
    var trackcmp_h = document.getElementsByTagName("head");
    trackcmp_h.length && trackcmp_h[0].appendChild(trackcmp);
}
</script>

2 个答案:

答案 0 :(得分:1)

您需要按如下方式引用iFrame:

window.frames [&#39; myIFrame&#39]。的document.getElementById(&#39; myIFrameElemId&#39);

所以在你的情况下:

window.frames [&#39; wufooFormm73jde715tzew1&#39]。的document.getElementById(&#39; form227&#39)

答案 1 :(得分:1)

请尝试下一个代码:

document.getElementById('wufooFormm73jde715tzew1').contentWindow.document.getElementById("form227")

它适用于嵌入式iframe。但是,如果iframe中的网页是从其他域(例如google.com)加载的,那么您将无法执行此操作。这是因为浏览器的政策。