How Can i know using PHP, Whether the current request is from a popup window or from a normal browser window ?
--
Thank you
if you open popup yourself you can open window with query string like this:
window.open("page.php?popup=1");
then you can check this query string in php like this:
if(isset($_GET['popup'])){
echo 'popup window';
}else{
echo 'normal window';
}
You cannot do it with PHP.
You may want to use `$_SERVER['HTTP_REFERER'] to determine how the user reached the page to determine if it's a popup window.
If you have the option of using JQuery then you can use $(window).height(); to determine the size of the window.
With raw JS things get a little more complicated: http://andylangton.co.uk/blog/development/get-viewport-size-width-and-height-javascript
PHP is server side, browser window are client side. there is no way to know this using only PHP... you need a client side language that can tell the difference, and pass it through to your PHP script.
But as was already said in the comments, there is no inherent difference between a popup and a 'normal' browser window... just as there is no difference between 2 instances of a browser and 2 tabs in the same browser window...
Related
Is there a way in PHP or javascript to know whether the user clicked the 'ok' button once a download box popup?
I wanted to count how many download have made to that specific file,
I wanted to done it this way by detecting if 'ok' was clicked.
I don't think that is possible, even with javascript. Because, that download dialog is beyond the scope of javascript. There are no solution to your problem.
You can only add counter +1 to your download counter without knowing that the user are actually clicking 'OK'.
The force download method in Google Chrome is different. This will download the file automatically if you click on the link. No messages like this will be displayed. So if you are finding some method for the above problem, this will not be a cross browser compatible solution.
How can I determine if a page is opening in an overlay or in a browser window?
To be more exact, it's download page behavior from GitHub: if you click on the Downloads button from this page, it will open a facebox overlay. However, if you copy the address from the respective link and paste it into a new tab, it will open as a new page.
So how do you check to see where is the page opening (assuming PHP)?
Edit:
This was what I was looking for.
I think you need to do the checking on the client using JavaScript and PHP is not going to help you on this one. As far as I can tell from your post you need figure out how the page is loaded. Probably it is an iframe or such. Of that you must be able to retrieve the loaded address.
I don't know why you would want to check that, but as you can see the link has an id="download_button". And in the bundle_hithub.js file the download_button is associated with the popup event. I don't know how exactyly, it's hard to read those single-line compressed JS files.
if the page that is going to be loaded has the following script
<script type="text/javascript">
window.location = "http://page-loads";
</script>
it won't run when loaded through an ajax call (since the page will most likely be appended with an innerHTML way resulting in the script being appended in the document, but not ran)
but when opened solely in the browser window - the script will run taking the user away to the desired destination!
Is there any way possible to detect if a user has disabled JavaScript after load of the page so that <noscript> tags are rendered? Server side or client side is fine.
You could try putting an image inside the <noscript> tag, which would point to a php file of yours, which in turn it should return an image. This could allow you to know in the server that the user has Javascript disabled.
How to identify the user: you could rely on the session, or set an ID to the url of the image.
You could use the answer on this question as an example on how to server image files from a php script where you could add your logic to detect if the user has js disabled:
Return a PHP page as an image
Here is an idea I got from a book long time ago
<script>
document.cookie= "js_enabled=true";
</script>
Use the above on some first page that you see. Then check for that cookie on the next request to see if javascript is enabled. Of course this has the same flaw if cookies are disabled.
no... any kind of such detection after the page is loaded would have to be detected with js, and if it's disabled, it can't even do anything if it is.
Why not just render the NOSCRIPT tags all the time? That's the point of that tag, to provide content when JS is disabled. If the user is seeing what's in the NOSCRIPT's then they clearly don't have JavaScript enabled.
You could also have a JavaScript AJAX call fire at page load. If your server recieves a request for the page, but then does not receive the AJAX call by the client within the standard loading time frame, then the server can assume the client doesn't accept JS. Not perfect mind you, but you are dealing with client-side JS here.
I don't think there is really a good way to do server-side JS detection. <noscript> is the semantic way to specify non-javascript content - so I suppose rather then detect if JS is disabled, you should detect if it is enabled. You can hide the detection by default, and put a <style> block inside the <noscript> to unhide.
Can I Stop or interrupt PHP script for particular time?
I would like to implement logic like below:
on mydomain.com/index.php there will be flash appear showing some intro of a product for suppose 20 sec. Once it complete, on same index.php page the home page of site will appear.
I am not aware about flash (action script).
Is it possible in PHP or Javascript ?
Usually "splash pages", as the're called, are made up of a seperate page.
In flash you can use the following code (Actionscript 3). Put it int the last frame, or use an event listener to redirecrect when the file is finished. The actual redirect looks like this:
getURL("http://www.woursecondpagehere.com", "_self")
Where you place it is up to you.
EDIT: I think that this is a reliable solution because this guarantees (if implemented correctly) that the page won't move until Flash is done. CSS and Javascript will work fine too.
There isn't a need to interrupt PHP in the scenario given. Though I think what you want is to load the rest of the HTML after a certain event occurs.
If thats the case then you can use AJAX to load the additional HTML from the server. Or you can use CSS to hide that content and show it after a certain point.
The META Refresh tag is probably not what you want since it will redirect the user after 20 seconds, regardless of how long it took to load your Flash file, then play it. Since the speed of the user's connection cannot be reliably predicted, you will probably end up with a poor user experience.
What you want to do is definitely possible but it will involve some interaction between the Flash object and the rest of your page. If you could do as Moshe suggested and simply have the Flash object redirect the user's browser to your actual home page with content on it, that would be easier.
If you insist on keeping everything on the same page, one way to do it is to call a Javascript function from the Flash object once it's finished playing. The function you call should be written to hide the Flash object and/or it's container and display the container () with all of your content that you're ready to show.
See this Codefidelity blog post for a quick tutorial on how to call JS functions from Flash.
Also, to clarify, you won't be interrupting or changing when your PHP script runs. That runs on the server before the page is created and sent back to the user's browser. All you need to do is structure the HTML/CSS of your page to have two DIVs: one with the Flash object in it and the other with all your normal page content. However, set the CSS to only show the DIV with the Flash object, then finally use Javascript to hide that DIV and show the one with the content in it.
Try this,
write the your flash (splash screen) <embede> code in index.html and simply use javascript redirect function with javascript timer functions to redirect to index.php where you actual content is there.
something like...
window.location = "http://your.domain.name/index.php"
or
location.href = "http://your.domain.name/index.php"
use setTimeout() to call redirect after specified time.
How do I create a loading overlay(with loading gif) while php script runs and returns data
PHP is a server-side language and what you're looking for is something that interacts with the browser on the clientside.
You're probably best of using a solution involving AJAX - for example using Jquery:
When the user loads the page, make an AJAX call that runs your script. Show a div that displays your 'loading' gif. When the AJAX call finishes, hide the div with your 'loading' gif.
You need to provide more information as to what to show and when to show the image. but to start with here is post about hot you can show a "loading" message (gif) using php and JQuery.
Use AJAX-like technologies and 2 php-scripts. The first should output only "loading..." div and start of AJAX-request to the second one, which returns the full content of your page.
PS: actually, I'm not sure if you understand, that "loading" exists on client-side browser as php's output, but php script runs on server before your browser gets it's output... read more about how HTTP and web servers work - this knowlege is quite neccesary for any good web-developer.