Check if a page is opened in an overlay - php

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!

Related

Bot friendly ajax page

I'm trying to code a seo friendly ajax portfolio right now. My goal is to provide javascript effects to users and normal html to bots/users without js.
Files:
index.php (starting point of my program)
aboutme.php (contains html code for "about me")
contact.php (contains html code for "contact")
The idea:
User visits index.php and clicks on "About me" -> loading animation appears -> aboutme.php gets loaded with ajax -> history.pushstate rewrites the url to aboutme.php.
-> When the user shares the current website url on fb/twitter/g+ the bots will get the correct title, body etc., as it is the normal html page without any javascript.
But my problem is: If other users open that page, they see directly the content. But I want to show them a loading animation first until the data got loaded with ajax (similar as they click on a link).
How can I achieve such an approach? Thank you very much!
Best way to do this, create a javascript file. Write the link tag into "head" part. This will make the javascript file downloaded before content. Javascript shows the animation, but at the same time browser will be downloading the content already in the background. On "document ready" event, stop animation.
This will let bots to access the content directly. Because javascript won't work for them.
To make your ajax content crawlable see https://developers.google.com/webmasters/ajax-crawling/, Bing supports this as well. Or use the HTML5 pushState, see http://www.seomoz.org/blog/create-crawlable-link-friendly-ajax-websites-using-pushstate, https://github.com/blog/760-the-tree-slider etc.
I've always thought this is more effort than its worth(generally), but to answer your question:
index.php, aboutme.php, contect.php should deliver full html.
certain links should have js event handlers intercept the click, and instead of loading aboutme.php, they load aboutme-content-only.php in the background. then update the dom and push state etc...
this way the site can easily degrade for those users who are first time visitors, as well as those whose browsers dont support push state or javascript.
I think that it is not a problem at all, keep your href of links as usual, then using JavaScript or jQuery change the default behavior of clicking link to load the linked contents with ajax.

Force PHP download script pops up a blank page, is there a way to close it?

The PHP file is ran with headers to force a download (from flash/as3 project), but it also pops up a blank page. Is there a way to close that after?
I don't think users want blank page popups springing up.
What I thought would work, but apparently not:
echo ("<script>window.close();</script>")
You can't echo something since that's part of the output of the script producing the file they're downloading. You wrote that JavaScript into the file. There is no separate webpage where you can put code like that.
You take care of it on the code that's starting the download (tricky stuff like javascript writing a 1x1 pixel iframe pointing to the download URL) or accept that you don't control browser behavior like this.

php + javascript open a link in new weindow (tab) automatically

I have 100 links for example, in a file. The idea is to loading to a php page, it loads the links file, it reads the first line and gets the first link. Then it opens it in a new window of browser, after 5 seconds the page refreshes itself and it gets the second link from the file and opens it in a new window again.
Now, I can do the whole thing by php, But I don't know how to open the link in a new window automatically without any click. and I guess it might be possible through JS.
Thanks for help :)
window.open('http://www.someurl.com','NameOfWindow');
There are also attributes you can keep specify to have more control. See http://www.pageresource.com/jscript/jwinopen.htm

Need help in downloading file with header() function

I'm trying to explain as best as I can, sorry for my English.
I have a list of links, each linked to a php file with an id by parameters (ex. download.php?id=1 or ?id=2 and so on).
This file create a new instance of a class witch return the correct header of the files so it displays the save dialog box of the browser.
Now I need to check if the files is already downloaded in past (The first time you downloaded it I add a field on the mysql db).
This checks go ahead if you haven't download the files, else return false.
Here is the problem, when it returns false or something else the browser redirect me to the download.php file, so I get a blank page or what I'm echoing.
I need that if the file is already download it show me a js alert for advice ppl.
Hope you can understand what i mean.
Thanks for help
Technically you can without ajax, the download.php can output the following if the user has already downloaded the file:
<script>
alert('It was false - you already have the file!');
window.back();
</script>
Just depends how well it integrates with your site. Not tested but thats the general idea.
it's too late to show a js alert in that case, you'd need to do something like ajax to check whether the file has been downloaded, and then show the alert or start downloading the file then.
once your web browser has started loading a new url (eg download.php) then it is too late, you are already navigating away from the current page.
So you've got a page that looks like:
1. file1
2. file2
3. file3
and they've got links to the download script on each. If you want to prevent multiple downloads, you do it in two places. Here on the main file list page, and on the download.php page. When the user clicks on one of the files, you have an onclick handler remove the link from the clicked file. This can be done by refreshing this page (and simply not adding the download link when the page is generated), or using some DOM manipulation to remove the tag around the filename.
The download page will also do checks if the file's been sent previous and can handle that condition itself.
Doing so in both places will degrade nicely if for whatever reason the client doesn't have Javascript enabled.
You need to handle it in two places for the best behavior.
Determine if the user can download the file when you generate the download page, and don't create links for files that can't be downloaded.
To handle the case of someone having multiple windows open or otherwise downloading a file without reloading the downloads page, check if the user can download the file in download.php before sending any headers. If he can't, send a redirect back to the download page:
header("Location: downloads.php?error=repeat_download");
exit;
…and use the error parameter to include a message at the top of the file list explaining what happened.

Stop or interrupt php script for particular time

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.

Categories