| | |
How do I add this javacript code into a php coded page!
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Solved Threads: 0
Hi there all!
I do not have a great knowledge of php but I do know basic html.
I have a javascript popunder script that I would like to try on my site that runs
on a php script.
I know how to insert this script into an html page but I can't get it to work in php.
I inserted the javascript that would go in the <head> of the html, before the <?php
tag. But i am not sure how to insert the <body onload='init()'> part of this into the php
page?
Can someone here possibly help me with this.
Thanking you in advance!
The full Javascript code is listed below:
I do not have a great knowledge of php but I do know basic html.
I have a javascript popunder script that I would like to try on my site that runs
on a php script.
I know how to insert this script into an html page but I can't get it to work in php.
I inserted the javascript that would go in the <head> of the html, before the <?php
tag. But i am not sure how to insert the <body onload='init()'> part of this into the php
page?
Can someone here possibly help me with this.
Thanking you in advance!
The full Javascript code is listed below:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<head> <script type='text/javascript'> function doOpen(url) { if (get_cookie('popunder')==''){ // attempt to open the popup win = window.open(url, 'test', 'toolbar,status,resizable,scrollbars,menubar,location,height=600,width=800'); if (win) { // popup successfully created win.blur(); setTimeout('win.focus();',10000); } else { // popup was not created. showPopupMessage(url); } var today = new Date(); today.setTime( today.getTime() ); expires = 1 * 1000 * 60 * 60 * 24; var expires_date = new Date( today.getTime() + (expires) ); document.cookie="popunder=yes;expires=" + expires_date.toGMTString() } return win; } function init() { var win = doOpen('http://www.yoursite.com/'); } function showPopupMessage(url) { if (!document.createElement) { return; } var elmDiv = document.createElement('div'); if (typeof(elmDiv.innerHTML) != 'string') { return; } elmDiv.id = 'popupmessage'; elmDiv.style.cssText = 'position: absolute; left: 300px; top: 225px;' + 'width: 350px;' + 'color: 000099; ' + 'background-color: white; ' + 'font-weight: bold; ' + 'font-size: 14; ' + 'border: solid black 2px; ' + 'padding: 1em;'; var html = 'Thank you for visiting this-site.com. ' + 'Please enjoy your stay. ' + 'Visit back tomorrow for more exciting news! ' + '<p align="right">' + '<a href="#" ' + 'onclick="document.cookie=\'popunder=\'; win = doOpen(\'' + url + '\'); hidePopupMessage(); return false;">' + 'close</a>' + '<\/div>'; document.body.appendChild(elmDiv); elmDiv.innerHTML = html; } function hidePopupMessage() { var elmDiv = document.getElementById('popupmessage'); if (elmDiv) { elmDiv.parentNode.removeChild(elmDiv); } } function get_cookie(Name) { var search = Name + "=" var returnvalue = ""; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search) if (offset != -1) { // if the cookie exists offset += search.length end = document.cookie.indexOf(";", offset); // set the index of beginning value if (end == -1) // set the index of the end of cookie value end = document.cookie.length; returnvalue=unescape(document.cookie.substring(offset, end)) } } return returnvalue; } </script> </head> <body onload='init()'>
Last edited by Tekmaven; Jul 31st, 2008 at 6:31 am. Reason: Code tags
You just put all your javascript statements in echo like following:
javascript Syntax (Toggle Plain Text)
echo'<script language="javascript">window.location.href="example.php";</script>';
Last edited by Shanti Chepuru; Jul 31st, 2008 at 4:33 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
use print in stead like:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
print '<script language="javascript">window.location.href="example.php";</script>';
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Select click or change
- Next Thread: How to call a javascript function other than form
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxjspservlets array autoplay beta blackjack boarder box browser captcha captchaformproblem cart close codes column css date debugger decimal dependent design developer dom download element embed enter error events firefox flash focus form frameworks game gears getselection google gwt gxt hiddenvalue highlightedword hint html ie7 iframe index java javascript javascripthelp2020 javascripts jquery jsp libcurl listbox maps marquee masterpage media menu mimic mp4 onerror onmouseover parameters paypal php player position post problem programming prototype rating redirect safari scale scriptlets search security select size software solutions sources starrating synchronous toggle tweet unicode variables w3c web webkit webservice window windowofwords xml






