Here is a situation. We have a search feature which uses ajax so that search results can be updated when user changes one of the search filters. The search results page also has 3 ad units that are using iframes. We are using iframes so that when usees use pagination to go different pages or update search results using search filters, the ads can be refreshed.
Now the problem is if user uses pagination to go to different pages and then try to use browser back button, it does not work properly because when you change iframe source, browser add this in history
I would apprecaite any help on how to solve this issue.
You may want to consider loading ads dynamically (i.e. AJAX), instead of using iframes. So, you would simply use a <div> to display the ad (loaded with AJAX) instead of an <iframe>.
Mayby try location.replace("http://yourPage...") to replace the browsers last history entry after iFrame load?
Related
I was reading up on ajax and how it empowers us to exchange data with a server behind the scenes and consequently avoid full page reloads. My confusion lies here, I don't really understand what full-page reloads mean. I think it's probably cause I've been working with ajax/react since the start I guess and have not really seen any webpage of mine fully reload when I access stuff from a database or an api.
It'd be great if someone could explain what they are and why did we need them before ajax?
A full page load is where the entire page is downloaded from the server. A page typically consists of several sections: header, footer, navigation, and content. In a classic web application without AJAX, a user clicks on a link to another page, and has to download the full page, even though only the main content is changing. The header, footer, and navigation all get downloaded again even though they don't change.
With AJAX there is the opportunity to only change the parts of the page that will change. When a user clicks on the link, JavaScript loads just the content for that link and inserts it into the current page. The header, footer, and navigation don't need to reload.
This introduces other problems that need attention.
When AJAX inserts new content into the page, the URL doesn't change. That makes it difficult for users to bookmark or link to specific content. Well written AJAX applications use history.pushState() to update the URL when loading content via AJAX.
There are then two paths to get to every piece of content. Users can either load the URL containing that content directly, or load the content into some other page by following a link. Web developers need to test and ensure both work.
Search engines have trouble crawling AJAX powered sites. For best compatibility, you need to employ server side rendering (SSR) or pre-rendering to serve initial content on a page load that doesn't require JavaScript.
Even for Googlebot (which executes JavaScript) care must be taken to make an AJAX powered site crawlable. Googlebot doesn't simulate user actions like clicking, scrolling, hovering, or moving the mouse.
Content needs to appear on page load without any user interaction
You must use <a href=...> links for navigation so that Googlebot can find other pages by scanning the document object model (DOM). For users, JavaScript can intercept clicks on those links and prevent a full page load by using return false from the onclick handler or event.preventDefault() in the click handler.
I was wondering, is Ajax only for dynamic content update or can it also, say, create a few buttons in a given div depending on what action a user chooses in another div? For example, if the login page and first page look very similar by only a few buttons, once proper login credentials are entered, can I use Ajax to make the other three buttons appear once logged in properly, rather than going to a whole another web page that has those buttons hard coded in the html/css? If this is possible, I'll take pointers to any tutorials. Thanks.
AJAX is just for creating HTTP requests using javascript, in order to prevent full page requests.
What you can do is to process the login request using AJAX and then, depending on the response you send, to display an error or update the DOM with the logged in interface.
If you just want to change the DOM, you use javascript directly (jquery would help) but no AJAX is needed.
I have a bookmarklet that opens a dialog (in reality an iframe) and extracts some information. When the dialog is dismissed I want to put that information into edit text fields on the original page in the browser (like the way LastPass will automatically fill-in login forms on a page).
Is this possible? I'm thinking that same-origin-policy will prevent this, but maybe there is a way (without installing extensions such as greasemonkey, etc).
Edit: to be more precise: the bookmarklet appends a DIV to the original page; that DIV contains an IFRAME that loads my page; this page fetches some information; once this information is fetched within the IFRAME I want to remove the DIV and (somehow) put that information into the original page.
The issue I face is communicating the information in the IFRAME back to the original page.
What you are looking for are the functions addEventListener and postMessage.
Relevant links:
http://caniuse.com/#feat=x-doc-messaging
How do you use window.postMessage across domains?
I am working on classified ads project in asp.net mvc3. I am facing problem in filter search page I want to change the URL without loading the whole page like Facebook or Linkedin before change:
http://localhost:4847/Category/Clothing/
after change when user remove category:
http://localhost:4847/Category/
And when user select category it should be change to append category as I show on top.
I am using ajax for filter search
You can make use of the Html5 History API
Anyway this is an Html5 feature and not all browsers may support it. In this case I would suggest directly using a plugin that degrades to hash changes if not supported, like History.js
This is fundamentally the same question as how to fix the browser history back-forward buttons. Checkout What is the best back button jQuery plugin?, it really could help you alot!
My website uses ajax.
I've got a user list page which list users in an ajax table (with paging and more information stuff...).
The url of this page is :
/user-list
User list is created by ajax. When the user click on one user, he is redirected to a page which url is : /member/memberName
So we can see here that ajax is used to generate content and not to manage navigation (with the # character).
I want to detect bot to index all pages.
So, in ajax I want to display an ajax table with paging and cool ajax effetcs (more info...) and when I detect a bot I want to display all users (without paging) with a link to the member page like this :
JohnBob...
Do you think I can be black listed with this technique ? If you think so, could you please provide an alternative solution by keeping these clean urls and without redeveloping the user-list (without ajax) ?
Google support a specification to make AJAX crawlable:
http://code.google.com/web/ajaxcrawling/docs/specification.html
I did an experiment and it works:
http://seo-website-designer.com/SEO-Ajax-Google-Solution
As this is a Google specification, you won't get penalised (unless you abuse it).
Saying that, only Google support it at the moment (AFAIK).
Also, I believe following the concept of Progressive Enhancement is a better approach. That is, create a working html website then make the JavaScript enhance it
Maybe use the urls with an onclick to trigger your AJAX scripting? Like
Some URL
I don't think Google would punish you for this, you primarily use JScript, but you do provide a fall back for their bot, so your site doesn't get any less accessible.
EDIT
Ok, I misunderstood. Then my guess would be you basically have two options:
1. Write a different part of your site where bots end up, or,
2. Rewrite your current site to for example always give a 'full' page, with an option to only get, say, the content div. Then you can get only the content with JavaScript, but bots will always get a nice page.