2016-09-10 108 views
1

我試圖在幾個WordPress頁面中嵌入一個iFrame。每個頁面將使用不同的iFrame內容。這是針對商業網站的,因此需要第一個iframe作爲客戶的登錄。在不同的WP頁面隨後的I幀將是產品搜索,結賬......((我的問題是在底部))如何在關閉/ body標籤後在WordPress中添加Javascript

  1. 在header.php中,我把我需要包括一些初始代碼每個WordPress頁面。

  2. 我在每個頁面的主體內添加了iframe。

  3. 我需要將iframe初始化爲特定的iframe內容。我想將此代碼收盤</body>標籤之後,如下所示:


<html> 
    <head> 
    <script> 
     var absDomain = "http://www.webstore.com/" 
     var iframeObj; 
     var timestampString = '' + new Date().getTime() + '' 
     document.write('<script type="text/javascript" src="' + absDomain + 'Support.js?'+timestampString+'"><\/script>'); 
     document.write('<script type="text/javascript" src="' + absDomain + 'ProductSearch.js?'+timestampString+'"><\/script>'); 
     document.write('<script type="text/javascript" src="' + absDomain + 'Environment.js?'+timestampString+'"><\/script>'); 
     function gotoIframe(theLocation){ 
     var timeStamp = ""; 
     iframeObj = document.getElementById("iframeContent"); 
     timeStamp = "&" + new Date().getTime(); 
     iframeObj.src = absDomain + theLocation + "?iframe=yes" + timeStamp; 
     } 
     function executeIFrameProductSearch(str1, str2){ 
     goTo_CategoryForIframe(str1, str2, document.getElementById("iframeContent")); 
     } 
    </script> 
    </head> 
    <body> 
     <!-- iFrame embedded below --> 
     <iframe id="iframeContent" style="width:100%;height:500px; " src=""></iframe> 
    </body> 
    <script> 
     //script needed for initial iframe page and iframe support. 
     iframeObj = document.getElementById("iframeContent"); 
     gotoIframe("CustomerLogin.html"); 
    </script> 
    </html> 
    //After the above code section (after the </body> tag) is embedded into the Login page, I expect to use: 
    //Customer Login: 
    <a href="javascript:gotoIframe('CustomerLogin.html')">Customer Login</a> 
    //Product Search: 
    <a href="javascript:gotoIframe('ProductSearch.html')">Product Search</a> 

問:我在哪裏插入這對我的每一個具體的WordPress網頁的結束標記之後的代碼?謝謝。

+0

我沒有得到怪異離奇,並要求該結束標記後放東西footer.php。你能詳細說明嗎? –

回答

0

將腳本標記放在body標記後是無效的,但如果您確實想要這樣做,您可以查看主題的footer.php。

例如,您可以在footer.php發現這樣的代碼:

<?php 
    </div><!-- close tag for content container --> 
?> 
    <footer> 
    <!-- footer content --> 
    </footer> 
    </body> 
    <!-- here is the place to put your code --> 
</html> 
+0

謝謝@ucheng。這就是我一直在尋找的。 – Petr

+0

歡迎您@Petr請投票或接受答案。謝謝! – ucheng

0

複製並在你的functions.php文件

 //alert(); enable alert to test 
      //script needed for initial iframe page and iframe support.`function your_function() { 
echo '<script>` 
      iframeObj = document.getElementById("iframeContent"); 
      gotoIframe("CustomerLogin.html"); 

    </script>'; 

}

ADD_ACTION粘貼功能( 'wp_footer','your_function',100); //這會將腳本添加到每個頁面的正文標記之後

其他選項將是 //其餘選項將位於此行或其他位置上方的其他位置!

function yourprefix_scripts_after_opening_body_tag(){javascript} file_get_contents(get_template_directory()。'/js/opening-body.js'); echo''。 $ javascript。 ''; }

add_action('yourprefix_after_opening_body_tag','yourprefix_scripts_after_opening_body_tag');

將此代碼粘貼在要顯示

相關問題