Thread: Javascript in PHP
Results 1 to 5 of 5
Related
-
how to stop javascript via another javascript Forum: Javascript Forum
Replies: 0 -
is there a difference between <script language="javascript> and <script type="text/javascript"> Forum: Javascript Forum
Replies: 8 -
Is it possible to stop a javascript function w/ other javascript code? Forum: Javascript Forum
Replies: 5 -
Javascript / css Forum: Javascript Forum
Replies: 1 -
JavaScript Forum: Javascript Forum
Replies: 2
-
04-22-2004, 11:58 AM #1
Javascript in PHP
I'm trying to insert a counter into a PHP page using Javascript.
The original code for the counter is:
HTML Code:<script language="javascript"> var data, p; var agt=navigator.userAgent.toLowerCase(); p='http'; if((location.href.substr(0,6)=='https:')||(location.href.substr(0,6)=='HTTPS:')) {p='https';} data = '&r=' + escape(document.referrer) + '&n=' + escape(navigator.userAgent) + '&p=' + escape(navigator.userAgent) if(navigator.userAgent.substring(0,1)>'3') {data = data + '&sd=' + screen.colorDepth + '&sw=' + escape(screen.width+ 'x'+screen.height)}; document.write('<a href="http://www.ecounters.com" target="_blank" >'); document.write('<img border=0 hspace=0 '+'vspace=0 src="http://www.ecounters.com/counter.php?i=310' + data + '"> </a>'); </script>
PHP Code:echo '
<script language="javascript">
var data, p;
var agt=navigator.userAgent.toLowerCase();
p='http';
if((location.href.substr(0,6)=='https:')||(location.href.substr(0,6)=='HTTPS:')) {p='https';} data = '&r=' + escape(document.referrer) + '&n=' + escape(navigator.userAgent) + '&p=' + escape(navigator.userAgent)
if(navigator.userAgent.substring(0,1)>'3') {data = data + '&sd=' + screen.colorDepth + '&sw=' + escape(screen.width+ 'x'+screen.height)};
document.write('<a href="http://www.ecounters.com" target="_blank" >');
document.write('<img border=0 hspace=0 '+'vspace=0 src="http://www.ecounters.com/counter.php?i=310' + data + '"> </a>');
</script>
';
Parse error: parse error, expecting `','' or `';'' on line 8,
which is the '; line in the script.
After replacing '; with `'," and `';" I still end up with the same error message.
Any help in this would be appreciated. Thanks in advance.
-
04-22-2004, 01:13 PM #2
Hiya,
replace the ' with \' , that should do it.If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
04-29-2004, 08:21 PM #3
Just put your code between tags {capture} {/capture}
Isn't it?
-
08-25-2004, 01:18 AM #4
You could also simply close your php tags then write your js as you normally would and then open your php tags again.
eg:PHP Code:<?php
// some php code here
//now close your php tag
?>
<script language="javascript">
var data, p;
var agt=navigator.userAgent.toLowerCase();
p='http';
if((location.href.substr(0,6)=='https:')||(location.href.substr(0,6)=='HTTPS:')) {p='https';} data = '&r=' + escape(document.referrer) + '&n=' + escape(navigator.userAgent) + '&p=' + escape(navigator.userAgent)
if(navigator.userAgent.substring(0,1)>'3') {data = data + '&sd=' + screen.colorDepth + '&sw=' + escape(screen.width+ 'x'+screen.height)};
document.write('<a href="http://www.ecounters.com" target="_blank" >');
document.write('<img border=0 hspace=0 '+'vspace=0 src="http://www.ecounters.com/counter.php?i=310' + data + '"> </a>');
</script>
<?php
//now we reopen the php tags
//put in somew more php code and finish off your page
?>
Hope it helped some.
-
09-22-2004, 08:07 PM #5HTML Code:
_
Last edited by blah; 09-22-2004 at 10:56 PM.
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum