Killersites.com Homepage Welcome Guest   |   Register  |  Login
Login Name Password
  Search  
  Index  | Recent Threads  | Unanswered Threads  | Who's Online  | User List  | Help


Quick Go »

No member browsing this thread
Thread Status: Active
Total posts in this thread: 13
Posts: 13   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 1836 times and has 12 replies Next Thread
Male tca
Member
Member's Avatar


Joined: Aug 25, 2006
Post Count: 50
Status: Offline
Reply to this Post  Reply with Quote 
Javascript to PHP

I've found plenty of solutions for passing variables etc. from JS to PHP and vice versa, but none of them seem to solve my problem.

I want to know if Javascript is enabled in the client's browser. If it isn't then I want to do something different. Obviously, if it isn't, then Javascript won't run. How can I capture this with PHP?

BTW, get_browser isn't updated on my server and I don't have access to change it.

TC
----------------------------------------
http://tcallaway.com

[Sep 21, 2006 7:46:02 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male admin
Advanced Member
Member's Avatar


Joined: Jun 14, 2003
Post Count: 2940
Status: Offline
Reply to this Post  Reply with Quote 
Re: Javascript to PHP

Interesting question.

My first inclination would be to attempt an AJAX call - if it works then you know the client supports Javascript.
----------------------------------------
Stefan Mischook

Video Tutorial Store | Web Templates
[Sep 21, 2006 9:30:43 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male LSW
Advanced Member
Member's Avatar

USA
Joined: Nov 27, 2003
Post Count: 6285
Status: Offline
Reply to this Post  Reply with Quote 
Re: Javascript to PHP

New site or revamp?

Just wondering why even use JS then, PHP can do anythig JS can do without being turned off...
[Sep 21, 2006 10:36:27 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male Robbkore
Member




Joined: Sep 20, 2005
Post Count: 62
Status: Offline
Reply to this Post  Reply with Quote 
Re: Javascript to PHP

Can you parse PHP on mouse events? I've never seen it done, not saying it's impossible! How bout PHP alert windows (also mostly used with mouse state)? Those can be handy for form-filing.

I'm not saying it cannot be done, I'm guessing there is some method for doing so. Just curious as to if it can.
[Sep 22, 2006 11:02:26 AM] Show Printable Version of Post    View Member Profile    Send Private Message    Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Male admin
Advanced Member
Member's Avatar


Joined: Jun 14, 2003
Post Count: 2940
Status: Offline
Reply to this Post  Reply with Quote 
Re: Javascript to PHP

Hi,

You cannot (directly) do any client-side parsing with PHP - PHP is a server-side language. That is to say that PHP does it's thing on the server, before the browser gets the page.

The process:


  • The user request a page (clicks on a link or types in a URL)
  • The web server gets the request and if it's a php page, sends the page to the php engine.
  • The PHP engine processes the php page and then sends back an ordinairy html page.
  • The web browser reads the page and places everything in its memory.
  • Javascript can now do things to the page.


That means you cannot trap for mouse events, spawn alert boxes or anything else that is browser specific with PHP. This has to be controlled via Javascript.
----------------------------------------
Stefan Mischook

Video Tutorial Store | Web Templates
[Sep 22, 2006 12:44:30 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male tca
Member
Member's Avatar


Joined: Aug 25, 2006
Post Count: 50
Status: Offline
Reply to this Post  Reply with Quote 
Re: Javascript to PHP

New site or revamp?



Just a new project that might become a new site. I'm using JS to show/hide contents of a block element (div, span, p, etc.). Very simple JS that changes the style of the block element from display:none to display:block or inline. Obviously this won't work with JS turned off in the browser.

Is there a way to do this in PHP? I haven't been able to find it if there is.

@admin, it looks to me that if JS is off, AJAX won't work either. Although I haven't studied AJAX at all and only given it an hour or two of research, all the AJAX calls I've seen use JS to begin with. Maybe I'm missing something?

TC
----------------------------------------
http://tcallaway.com
[Sep 22, 2006 2:50:18 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male LSW
Advanced Member
Member's Avatar

USA
Joined: Nov 27, 2003
Post Count: 6285
Status: Offline
Reply to this Post  Reply with Quote 
Re: Javascript to PHP

Ok, odd case where JS is needed... just not sure that it is really a good idea to do what you want to do.

What would be the default? If the text is available and the JS hides it that is OK.

But if the text is hidden with display:none ... when JS is not supported, the text is gone and falls away, the CSS command has removed it from the page and it is lost to anyone unless they turn of CSS too.

If you use JS in such a manner the default must make the text available for those who do not support JS.
[Sep 22, 2006 3:22:37 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male admin
Advanced Member
Member's Avatar


Joined: Jun 14, 2003
Post Count: 2940
Status: Offline
Reply to this Post  Reply with Quote 
Re: Javascript to PHP

Hi,

That is what I am saying - if the ajax doesn't work, you know js is off.

It is hard to come up with a design without knowing some details about what you are trying to do.

BTW: JS is usually off only about 10% or less .. depending on the site.
----------------------------------------
Stefan Mischook

Video Tutorial Store | Web Templates
[Sep 22, 2006 4:02:15 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male billyboy
Advanced Member
Member's Avatar


Joined: Sep 3, 2005
Post Count: 2206
Status: Offline
Reply to this Post  Reply with Quote 
Re: Javascript to PHP

Here's a bit of php code that may do what you want. If so, I don't see a need for javascript.
<?php
$pass = array('content1','content2','content3');
if (in_array($_GET['id'], $pass)) {
include 'includes/' . $_GET['id'] . '.php';
}
else {
include 'includes/content1.php';
}
?>
Create separate files containing the html for the content you want to be displayed and save them separately with a php extension. Put the names of those files in an array (in the example they're called content1, content2, content3 and are saved to a sub-folder called includes). Whatever file is named in the else statment will be the default visible when the page first opens.

Then write the links to show the contents of each file, replace mypage with the file name of your webpage :
<ul id="menu">
<li><a href="mypage.php?id=content1">Content 1</a></li>
<li><a href="mypage.php?id=content2">Content 2</a></li>
<li><a href="mypage.php?id=content3">Content 3</a></li>
</ul>
As far as providing an alternative if javascript is not available that is what the html noscript tags do.
----------------------------------------
Quiquid latine dictum sit altum viditur
----------------------------------------
[Edit 1 times, last edit by billyboy at Sep 22, 2006 6:28:06 PM]
[Sep 22, 2006 6:26:06 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male tca
Member
Member's Avatar


Joined: Aug 25, 2006
Post Count: 50
Status: Offline
Reply to this Post  Reply with Quote 
Re: Javascript to PHP

LSW: Ok, odd case where JS is needed... just not sure that it is really a good idea to do what you want to do.

Agreed, but we're in testing mode here and it might turn out to work.

LSW: What would be the default? If the text is available and the JS hides it that is OK.

The default would show all the text. Which is actually an RSS feed that is loaded in another place on the page. The page would be messy, but it will all be there. Ergo, if JS is off, PHP will change the style to show all the text. I'm also thinking of using this same concept to load pictures in a separate element (probably a table cell) from thumbnails along side the element. I've seen this done with JS, but if it's off if won't work then I can get PHP to link to a page with all the pictures.

admin: That is what I am saying - if the ajax doesn't work, you know js is off.

And that is what I'm saying. With my limited knowledge of AJAX I can't see how to make PHP get the null return.

admin: It is hard to come up with a design without knowing some details about what you are trying to do.

The file is on my web site (see my signature) re_rss.php. If you need the code I can upload it as a text file.

I can do it with PHP by reloading the page each time but I don't think you can show but one feed at a time with this method. With the JS you can see all the feeds you turn on and you can turn them off individually too. As for the thumbnail exchange I mentioned, if JS is off then each TN will link to the separate page.

admin: BTW: JS is usually off only about 10% or less .. depending on the site.

I'm aware of that too, but in the real estate business, every 10% counts. I'm not an agent, just a computer jockey, but RE is my bread and butter and I try to be as innovative as possible because it is so competitive.

TC
----------------------------------------
http://tcallaway.com
[Sep 22, 2006 6:34:35 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Posts: 13   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread