Jump to content

Calling javascript within PHP framework?


redgreen99

Recommended Posts

I am using a PHP CMS much like Drupal (it's called Omeka). I'd like to include an image carousel on my pages, and have only found Javascript that does this (no PHP, which would make things easier). I've read that I can include the Javascript in my php file by echoing the script something like below, but that is not working. Any help you can would be appreciated (as well as any PHP image gallery carousels you might have seen!). Thanks!

 

This is the actual Javascrip I wish to include:

<script type="text/javascript" src="javascripts/compressed.js"></script>
<script type="text/javascript">
$('slideshow').style.display='none';
$('wrapper').style.display='block';
var slideshow=new TINY.slideshow("slideshow");
window.onload=function(){
	slideshow.auto=true;
	slideshow.speed=8;
	slideshow.link="linkhover";
	slideshow.info="information";
	slideshow.thumbs="slider";
	slideshow.left="slideleft";
	slideshow.right="slideright";
	slideshow.scrollSpeed=4;
	slideshow.spacing=5;
	slideshow.active="#fff";
	slideshow.init("slideshow","image","imgprev","imgnext","imglink");
}
</script>

 

This is how I tried to work it into the PHP (but it doesn't work):

<?
echo "<script type=\"text/javascript\" src=\"javascripts/compressed.js\"></script> \n";
echo "<script type=\"text/javascript\"> \n";
echo "$('slideshow').style.display='none'; \n";
echo "$('wrapper').style.display='block'; \n";
echo "var slideshow=new TINY.slideshow(\"slideshow\"); \n";
echo "window.onload=function(){ \n";
echo "slideshow.auto=true; \n";
echo "slideshow.speed=8; \n";
echo "slideshow.link=\"linkhover\"; \n";
echo "slideshow.info=\"information\"; \n";
echo "slideshow.thumbs=\"slider\"; \n";
echo "slideshow.left=\"slideleft\"; \n";
echo "slideshow.right=\"slideright\"; \n";
echo "slideshow.scrollSpeed=4; \n";
echo "slideshow.spacing=5; \n";
echo "slideshow.active=\"#fff\"; \n";
echo "slideshow.init(\"slideshow\",\"image\",\"imgprev\",\"imgnext\",\"imglink\"); \n";
echo "}\n";
echo "</script>";
?> 

Link to comment
https://forums.phpfreaks.com/topic/160137-calling-javascript-within-php-framework/
Share on other sites

Well, you're not going to find any PHP-only carousels because PHP is a server-side language.  It can't do things like react to browser events or create animation.

 

A quick look through your code leads me to believe you have a scope problem.  Try placing the three lines before your window.onload event inside of that function instead.

Thanks for the explanation of server/client-side -- that makes sense.

Unfortunately, your idea didn't work. I think I might be able to move all the script to an external file and then just echo that -- I will post if it works.

Thank you for your help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.