i have a master php page and now i am loading different pages in a div of this master page using ajax. now i want to add a back button on the slave pages so that the div can loaded with its just previous slave page but the back button, i am using uses history.go(-1) that take me away from master page. has anybody any solution. Thanks in advance.
the code i am using is written below. but it is not working in ajax pages
Go back
My suggestions would be to use a framework for this purpose like backbone.js
Where you can setup routes just like on server side.
I feel this is the best way to do this on ajax sites.
Read tutorial on Manipulating browser history.
It mentions:
pushState, which is used for creating "entries" in the browser's history (with attached data about state), allowing to get back to some specific state you previously saved,
onpopstate event, that is fired when you go back or forth through the browser's history, and passes information previously saved for specific entry in the history (so you actually can read data previously saved by pushState for this specific entry),
In case pushState and onpopstate do not work for you, there is still some ability to work on the basis of onhashchange event (however limited).
The good news is that what you want to achieve is definitely possible. It is even implemented in many famous sites such as Twitter, GitHub, Facebook etc.
You can use the history functionality provided in newer browser. There is several libs that already provide functionality for you:
For JavaScript MVC applications:
http://documentcloud.github.com/backbone/#History
For mobile web pages:
http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/pages/docs-navmodel.html
For implementing a solution your self:
http://benalman.com/projects/jquery-hashchange-plugin/
Related
There several threads on SO regarding this, but I just need to know how to READ a cookie from siteb.com on sitea.com that opens siteb.com on a iframe, IF this is really the recommended way to go.
Based on this post the author says:
Cookies can be read in an iframe if they were set outside of the
iframe
But I have no idea how to achieve this. Let me explain a bit more about what im trying to design so maybe you can point me in the right direction.
siteb.com is my website, where users login and signup, each time they do, a cookie is set like many normal authentication systems.
sitea.com is a generic site, where I can insert html and javascript code, from sitea I need -if exists- to read the login cookie of siteb. I think an iframe on sitea loading siteb will do the trick, but again, i have no idea how to access that cookies inside the iframe. Is there an easy way to do this?
Another approach i was thinking is to use cross domain iframe communication techniques, but they are not elegant, way complex and some of them fails in certain browsers, the most robust ones uses jquery but I don't want to insert jquery on sitea.
Here's what you need: http://easyxdm.net/ - load this library on both sitea.com and the siteb.com iframe. It makes cross-domain parent-iframe communication "just work" in every browser, using the fastest method avaliable in each browser. (Also, the author, https://stackoverflow.com/users/128035/sean-kinsey does a fantastic job of helping anyone who has trouble with the library - just check the mailing list archives)
Then add a tiny bit of JavaScript to your siteb.com iframe to read cookies and pass them to easyxdm and then add a bit of JavaScript to sitea.com to set up easyxdm (including creating the iframe, I think) and receive the cookie value from it. There's lots of examples on the website to help you get started.
I successfully send data from Android to PHP and store in MYSQL database.
What I want is to display the data in my PHP page automatically without refreshing the page when data has been sent from and Android device.
Is this possible, possibly using jQuery with AJAX?
Please explain how it can be done or point me to a resource where I can find such information.
So you essentially want to update the page when data changes on the server.
Two main options come to mind:
1. Ajax poll
Use setTimeout in conjunction with an ajax call to periodically call the server and see if anything changed. You already mention jQuery, that's certainly a good place to start. Get familiar with http://api.jquery.com/jQuery.ajax/. This is probably going to be your best bet.
2. PubSub
I use http://www.pubnub.com/ on one of my sites for this very purpose. The browser subscribes to a pubnub channel, and the server publishes on that channel anytime something changes on the server. This is obviously more work to get setup up front, and more applicable for rich client-side applications (mine is a single-page app).
There are plenty of other implementations of PubSub as well.
I am creating a social networking site using php,jQuery and MySQL. I have a big doubt. How to dynamically update a user's home page when one of his/her friends does an action and if that has to appear on current user's page as soon as the friend has updated. I am new to this, please help me in this problem?
It looks like you're looking for a way to implement push functionality from your web server to a current user's page.
The push data will be sent as part of a friends' action or soon after (in a queued fashion), and once it arrives to the client Javascript should be used to update the view.
Some methods of doing that are described on the push technologies Wikipedia page.
You can add a JavaScript timer function in web page side. And regularly to check whether new information is gather.
If there is information, then add new information in the page or notice user.
This is a jQuery Timer.
This is function of jQuery.ajax(). You can use this function in jQuery Timer to check whether there have new information.
If there have new content, you can use "Adding elements to the DOM" to display them out. This is a reference for this topic, Adding elements to the DOM.
I think this way would be helpful.
I am developing an online learning system (PHP, MySQL and Javascript). I would like to track what pages and how long each users spent on each page. Ideally, I would like to record this in a MySQL database. My question is 2 fold:
1. What kind of fields would I include in my db table to record multiple pages accessed?
2. Is this problem best approached by server side only or by using javascript ? e.g. server side: hidden form fields with a page id attached, page id is passed to db and recorded?or Javascript: record all actions in Javascript variables and somehow pass to db at end of session?
Really I am just looking for some high level guidance on an approach as opposed to code snippets.
GF
PHP isn't my normal language, but I would think about creating a module of code that can be called from the top of each of your scripts, that basically logs away "I served this page, with these form variables, at xxx ... ". To be more precise, I would record that in a table.
If you need to know when the user left your page, for a page on another site or perhaps shut down their browser for instance, then a purely server side solution isn't going to cut the mustard. In that event, you are going to have to start thinking about JavaScript, and intercepting events - such as the onUnload event...
Have a read here...
While I know of no solution that can track individual users out of the box (I'm sure there are some), I am pretty sure you could customize Piwik to do this. Piwik aims to be a self-hostable alternative to Google Analytics. It is open source and build on Zend Framework and MySql.
Piwik collects usage statistics through a JavaScript tracking code and a Webbug image for fallback. Basically, what you would need to do is pass the logged in user's user id to the tracking script and then write a plugin that knows how to handle this information.
I have a Google calendar embedded on a webpage, with events related to activities the site is organizing. Some calendar events have links that redirect the user to a page, within the same website, which has more information and the option to enroll in the event.
The problem however, is that since the end of last month, Google imposed a redirect notice that doesn't even automatically redirect. The links I create on events are changed by Google and, once a user clicks on a link, a new tab opens leading to a page with a redirect warning that the user must click. Since I am providing the users with a link to within the same website this is very inconvenient and makes no sense at all.
I'd want the users to be able to click a link on the calendar and go through to the webpage with the relevant data.
Do you guys know how I can go around this warning?
My thought process:
Initially, I thought of using JS to rewrite the links but since the calendar's iframe is in a different domain, the browser won't allow it due to XSS exploits (AFAIK).
I could build my own AJAX calendar and sync it with Google's using the API, but that's a hell of a lot of work because of stupid "feature" that makes no sense. I like Google's calendar and I'd like to use it.
The third thing that I though of was that, instead of having an iframe with the calendar I could use AJAX to fetch the entire code on the frame's url. Then I'd just rewrite the links on the that code with JS. Could this work?
I would be REALLY thankful for any help. This is driving me insane!
Using Jon Cram's input I created a php script that parses the code and makes the adjustments. However I could only get that working for the html version. No AJAX for me. =(
The same origin policy will prevent JavaScript served from your domain from interacting with data served from a different domain.
You are therefore right in saying that option 1 won't work.
The same origin policy also applies to option 3 as you have stated it. JavaScript served from your domain won't be able to make a direct HTTP request to whichever domain serves the calendar code.
You will need to acquire and modify the calendar code, neither of which can be achieved with JavaScript using today's most commonly used browsers. When FireFox 3.1 and IE8 are in common use and Google serves the correct HTTP Access Control headers this could be achieved with JavaScript alone.
To modify code served from another domain, you will need to utilise some form of server-side process.
A server-side script will be able to request the calendar code. The same script can then modify the code as needed and output it in whatever form you require.
If it is a private internal site you could install greasemonkey on all clients (if they use firefox) and make a short script that fixes the urls. That only works if the original url is contained within google's redirecturl though.
If I had this problem I wound change the calendar provider, that's probably the easiest solution. I did a google search and found Kiko, looks like they might have what you need?
Simply remove the "http://" part of the URL. I am not sure why this works but it does!