View Single Post
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: "add this site to your bookmarks" in firefox

 
0
  #9
Jan 21st, 2007
To 'interact' between javascript and PHP, you have to either use PHP to create javascript code, or use XMLHTTP requests in javascript to access PHP scripts and then handle the output if neccessary.

You cannot write javscript code that directly invokes PHP code. javscript is processed on a client's computer; PHP is processed at the server as a page is requested. Javscript only ever runs after the PHP processor has done its work (and removed all PHP blocks from its output files)

That doesn't mean that you cant create javascript code based on or affected by a PHP process; it just means that the javascript in a PHP file will do what the PHP code tells it to do.

So, by the time javascript runs; this PHP code:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. addBookmark('mysite',<? echo 'http://mysite'; ?>)

will always end up as this javscript code:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. addBookmark('mysite',http://mysite);

And that code wont work because of quoting.

But this PHP code:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. addBookmark('mysite','<? echo 'http://mysite'; ?>');

Generates this code:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. addBookmark('mysite','http://mysite');

Which should work.
Plato forgot the nullahedron..
Reply With Quote