最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

basic php question. adding javascript to .php page - Stack Overflow

programmeradmin4浏览0评论

Hi i am not a php developer, ive never touched it before. but i have been asked to add a google shopping cart tracking code to a website. when someone completes an order then get sent to finishorder.php. when i go the finishorder.php file it looks like this:

include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();

which just looks like server script to me (coming from a background), so i presume i cannot add the javascript here, how does php decide get the layout for this page? how can i add the javascript code to this page.

Hi i am not a php developer, ive never touched it before. but i have been asked to add a google shopping cart tracking code to a website. when someone completes an order then get sent to finishorder.php. when i go the finishorder.php file it looks like this:

include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();

which just looks like server script to me (coming from a .net background), so i presume i cannot add the javascript here, how does php decide get the layout for this page? how can i add the javascript code to this page.

Share Improve this question asked May 4, 2011 at 10:59 philphil 7813 gold badges10 silver badges16 bronze badges 1
  • You need to find out what the view for your final page is. There must be a template file somewhere – JohnP Commented May 4, 2011 at 11:02
Add a comment  | 

3 Answers 3

Reset to default 13

You can do this:

include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();

echo '<script type="text/javascript">YOUR JS HERE</script>';

or

<?php
include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();
?>
<script type="text/javascript">YOUR JS HERE</script>

But I think that HandlePage() method will do something with our page so I'd look inside this method: class ISC_ORDER->handlePage() what it does... You can then echo your <script> within this method at appropriate place...

EDIT:

<?php
echo '<script type="text/javascript">//<!--
        alert("Hello to multiline JS script");
        alert("Do You get it?");
    //--></script>';
?>

You can add javascript inside a php code as

<?php echo "<script> alert('this is a javascript code')</script>"; ?>

You can add script in PHP page by 2 ways

The first way is to add it in PHP tags

<?php 
//PHP CODE
if($_POST['submit']){
echo '<script>alert('Hello')</script>';
}
?>

The second way is to add it after PHP code

<?php 
//PHP CODE
?>
<script>
alert('Hello');
</script>
发布评论

评论列表(0)

  1. 暂无评论