problem with ajax( page refresh) - php

hi im using ajax to extract all the pages into the main page but am not being able to control the refresh , if somebody refreshes the page returns back to the main page can anybody give me any solutions , i would really appreciate the help...

you could add anchor (#something) to your URL and change it to something you can decode to some particular page state on every ajax event.
then in body.onload check the anchor and decode it to some state.
back button (at least in firefox) will be working alright too. if you want back button to work in ie6, you should add some iframe magic.
check various javascript libraries designed to support back button or history in ajax environment - this is probably what you really need. for example, jQuery history plugin

You can rewrite the current url so it gives pointers to where the user was - see Facebook for examples of this.

I always store the 'current' state in PHP session.
So, user can refresh at any time and page will still be the same.

if somebody refreshes the page returns back to the main page can anybody give me any solutions
This is a feature, not a bug in the browser. You need to change the URL for different pages. Nothing is worse then websites that use any kind of magic either on the client side or the server side which causes a bunch of completely different pages to use the same URL. Why? How the heck am I gonna link to a specific page? What if I like something and want to copy & paste the URL into an IM window?
In other words, consider the use cases. What constitutes a "page"? For example, if you have a website for stock quotes--should each stock have a unique URL? Yes. Should you have a unique URL for every variation you can make to the graph (i.e. logarithmic vs linear, etc)? Depends--if you dont, at least provide a "share this" like google maps does so you can have some kind of URL that you can share.
That all said, I agree with the suggestion to mess with the #anchor and parse it out. Probably the most elegant solution.

Related

How do I find out that a link was seen

I'm trying to make a page with some links and when somebody clicks on a link, the score count will go up.
How can I find out the visitor who has really seen the page related to link? But not just click the link and close the page for score...
really seen means: page loads completed.
and my links opens in new window.
any solution?
You cant really see pages that aren't in the same domain. Chrome even puts them in a separate thread.
Back in the day you could have used a CSS exploit talked about here: https://developer.mozilla.org/en-US/docs/Web/CSS/Privacy_and_the_:visited_selector
If you really want to make a page with this kind of functionality you will have to make a browser plugin/extension.
You can include a nonce token in the link, and post that token to the server, render the page embedding that same token in some javascript and have the javascript post back the token when the page is done rendering. Seems kinda overkill though.
The only thing I could thing of is maybe make the link to like a redirect page on your site and then you could control to see if the page was loaded and then like after the page was loaded redirect to the actual webpage to link is intended. This way you know for sure that the user waited to view the webpage.
Other than that I don't think there is any other way for you to go about this.

Change window location without reloading some divs

As many of you have noticed, when you hit a link to switch from page to page in Google+ or facebook, the URL changes, the body changes but some parts of the page don't, like the chatbox. I believe AJAX can change a specific content of the page by requesting a PHP page from the server and get some results, but that won't change the URL.
Actually, I didn't know exactly how to search that in Google, so, any keywords/names/linkes will be strongly appreciated.
I'm using JQuery library for Javascript and Symfony2 framework for PHP, if this helps.
Look at the JQUERY load method.
http://api.jquery.com/load/
All you need to do is use a selector:
$('mydiv').load('newcontent');
Very powerful function. Look it up!
edit:
Sorry missed that url change. The trick alot of times with the URL is around the Hashtag. If you look closely at the URL there will be a "#" pound symbol in there somewhere. This allows the site to store current state without a reload.
Currently there is no way to change the URL in the browser save for the bit after the hashtag with out fully reloading the site.
you can either use iframe or ajax to keep some part of your page static.To change url either you can use hash hack.
window.location.hash = "pageidentifier"
or you can use the html 5 trick described in the url provided by arxanas

Updating URL without apparent reloading

I´m building a webpage that has a sort of catalog in it, which shows the current item and its description, and thumbnails for other items below it, if I click on a thumbnail of a different item, I have some script to change the description and the big image to the desired item. The problem is that I want this to reflect in the URL so the user could send the URL as a link to other to show the desired item. But I havent found a way to change the URL without having to reload the page, and for aesthethics, I dont want to reload the page.
Any ideas how to do this?
The solution is to use location.hash. Also, to implement it correctly, you might want to read this article from Google: Making AJAX Applications Crawlable
There is no reliable (cross browser) way to change the URL in the address bar without reloading the page - the very act of changing window.location.href (which I imagine is what your trying to do) tells the browser to reload the page (even window.location.href = window.location.href; will do it in some browsers).
I think you would have to put a [link to this page] element on the page and change that instead - you can easily populate it with the current URL either at the server side or using a window.onload function and manipulate it in the same way as you have been doing using element.value or element.innerHTML (depending on what type of element you choose to contain the link).
You can do it with hashes (see the window.location.hash property) but this can be messy programmatically.
The usual, currently-broadly-compatible way is to use a hash, e.g.:
http://myniftystore.com/catalog#11321R-red-shirt
then
http://myniftystore.com/catalog#11321B-blue-shirt
then
http://myniftystore.com/catalog#95748B-blue-slacks
...as you navigate items. You can change the hash on the page by assigning to the location.hash property, without reloading. This requires that you use some client-side script in the first place to figure out what to show when the user first goes to the URL (by examining the location.hash).
Google has a proposal out for how to make these things crawlable. Personally, I think they've really messed it up by requiring that weird hashtag (#!xyz rather than just #xyz), but if it's me or Google, I think I know who'll win. :-)
Coming down the pike there's the whole history API, but support isn't very thick on the ground yet (particularly not — cough — from certain vendors).

I'm not sure if I should use a redirect

I have an affiliate link on my webpage. When you click on the link it follows the href value which is as follows:
www.site_name.com/?refer=my_affiliate_id
This would be fine, except that the site offers no tracking for the ads, so I can't tell how many clicks I am getting. I could easily implement my own tracking by changing the original link href value to a php script which increments some click stats in a database and then redirects the user to the original page. Like so:
<?php // Do database updating stuff here
Header("Location: http://www.site_name.com/?refer=my_affiliate_id");
?>
But I have read some articles that say that using redirects may be seen by google as a sign of 'blackhat' techniques and they might rank me lower, unindex my site or even hurt the site that I'm redirecting too.
Does anybody know if this is true, or have any idea of the best way I could go about this?
Many thanks in advance
Joe
You could always do what Google does with search results. They have the link href normal, until the mousedown event. something to the effect of:
adlink.onmousedown = function(e) {
var callingLink = /* stuff to actually get the element here */;
callingLink.href = 'http://mysite.com/adtrack_redirect_page.ext?link=' + escape(callingLink.href);
}
Or something like that :P
So, Google will see a normal link, but almost all users will be redirected to your counter page.
Using a 301 redirect simple tells Google that the website is permamently moved. It should have, according to most random people on the internet and according to Google itself, no effect on your page-rank.
Actually I've read (can't remember where exactly) that this kind of redirect DOES HURT your rating. No, it won't "kill" your website nor the referenced, as far as I know (and please do check further), but it will hurt your site's rating as I said.
Anyway I'd recommend using some javascript to refer anything out of you domain - something like "window.open(....)" should do the trick, as Google will not follow this code.
There, refer to your tracking script which will redirect further.
You could use a javascript onClick event to send an ajax signal to your server whenever the link is clicked. That way the outgoing link is still fully functional, and your server-side script can increment your counter to track the clickthrough.

Opening Javascript based popup ads on the same page

I own an image hosting site and would like to generate one popup per visitor per day. The easiest way for me to do this was to write a php script that called subdomains, like ads1.sitename.com
ads2.sitename.com
unfortunatly most of my advertisers want to give me a block of javascript code to use rather than a direct link, so I can't just make the individual subdomains header redirects.I'd rather use the subdomains that way I can manage multiple advertisers without changing any code on page, just code in my php admin page. Any ideas on how I can stick this jscript into the page so I don't need to worry about a blank ads1.sitename.com as well as the popup coming up?
I doubt you'll find much sympathy for help with pop-up ads.
How about appending a simple window.close() after the advertising code? That way their popup is displayed and your window closes neatly.
I'm not sure that I've ever had a browser complain that the window is being closed. This method has always worked for me. (IE, Firefox, etc.)
At the risk of helping someone who wants to deploy popup ads (which is bound to fail due to most popup blockers anyway), why can't you just have the subdomains load pages that load the block of Javascript the advertisers give you?
Hey, cut the guy some slack. Popups might not be very nice, but at least he's trying to reduce the amount of them. And popup blockers are going to fix most of it anyway. In any case, someone else might find this question with more altruistic goals (not sure how they'd fit that with popups, but hey-ho).
I don't quite follow your question, but here's some ideas:
Look into Server Side Includes (SSI) to easily add a block of javascript to each page (though you could also do it with a PHP include instead)
Do your advertiser choosing in your PHP script rather than calling the subdomains
Decipher the javascript to work out what it's doing and put a modified version in the subdomain page so it doesn't need an additional popup. Shouldn't be too hard.

Categories