Reputation: 33
I am trying to embed an iFrame within several WordPress pages. Each page will use a different iFrame content. This is for a commerce site so needs the first iframe to be the customer's login. Subsequent iframes on different WP pages will be for product search, checkout... ((my question is at the bottom))
In the header.php I placed some initial code that i need to be included on every WordPress page.
I added the iframe within each page's body.
I need to initialize the iframe to a specific iframe content. I would like to place this code AFTER the closing </body>
tag as follows:
<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>
Question: Where do I insert the code that's AFTER the closing tag for each of my specific WordPress pages? Thanks.
Upvotes: 1
Views: 3620
Reputation: 1354
Copy and paste this function in your functions.php file
//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 ); // this will add the script after the body tag for every pages
other option will be // Rest of your functions.php above this line or wherever!
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' );
paste this code in footer.php where you want to display
Upvotes: 0
Reputation: 1164
It is invalid to put script tag after body tag, but if you really want to do that, you can look into the theme's footer.php.
For example, you may find code like this in footer.php:
<?php
</div><!-- close tag for content container -->
?>
<footer>
<!-- footer content -->
</footer>
</body>
<!-- here is the place to put your code -->
</html>
Upvotes: 0