Why are Google search results in UIWebView not triggering webViewDidFinishLoad? - ios

This is no doubt a more generic issue regarding web pages, but it is easily demonstrated with Google content.
When entering some search criteria on Google's home page the results are not triggering the webViewDidFinishLoad method. The same problem occurs when the coloured Google logo is replaced with some artwork linked to a feature page.
I suspect the page is not being fully loaded due to some javascript or ajax code, so is there a way of detecting this?

This is because Google are using AJAX to do this, the webViewDidFinishLoad delegate method is called when effectively a new resource is loaded into the webview - the equivalent to a page load in your browser, since Google are AJAXing this stuff, it isn't causing that method to get triggered.
There isn't any way to detect when parts of a page are loaded (javascripts, style sheets or ajax responses).
One thing you could be able to do is execute a line of javascript onto the web view that tells you the height of the page, by waiting until the height of the page changes you could know when a result has occurred, you will have to devise some other - more smart check of course when a search query is modified, but my idea would work for the initial google logo screen to the first results page.
Executing that JS every few seconds should be enough.
Hope that helps

Related

Backbone and jQuery Mobile App resetting after browser back button

I am building an app using Backbone.js and jQuery Mobile. On some pages in my app I have external href links and I'm running into an issue.
When a user clicks and external href link, get taken to the external site and then hits the back button. My app does not load from the proper page where the user originally left the app from.
In fact my entire DOM is reset so it looks like my site gets a complete refresh and doesn't keep any of its former state.
I have been trying to search for a solution but this issue is kind of hard to word out. I hope it makes sense.
Does anyone have any suggestions?
UPDATE
Stupid error on my part.. I had a bad id set on the page and it didn't load the data I had saved in the session for it when a user returns to the page.. Changed the id and all is well. Thanks!
Link
Make you external links open up new tabs.
If you have used one html with multiple pages solution then there's an explanation for this.
rel="external" will cause a full page refresh so last page location will not be remebered. When you return to the last location it will trigger new refresh and the first page will be shown again.
This can be prevented with a multiple html page solution.

Load adsense ads through page transition with jQuery mobile

I have been reading the web and trying out things for days looking for a way to show the Google Adsense ads through jQuery mobile transitions without breaking the ToS. I am a bit stuck so I turn to the wisest community.
The Adsense tag is made of three scripts (i) a general one, (ii) a list of slots and (iii) the display itself. The first two go in the <head>, the latter in the <body>.
I can display the ads on my first page just fine. The problem comes with page transition.
Since jQuery Mobile does not reload the <head>, an option is to prepare the googletag while loading the <head> the first time. This sets the limit to a maximum of three ads per page, which, across a whole site is not a lot. Plus it means that you will have to move ad <div> around, which is not so great either. Finally, it means that you may load ads and not display them until the user goes to the page where it belongs, if ever. Which is not so ToS compatible either.
Is there a way to load a fresh new ad on each transition? If yes, where do I put the Google scripts to make sure they load properly?
I found a way to get it to work in Google DFP with Adsense plugged into DFP. DFP is more flexible so it was easier.
Here is what I used:
In the <head>: I put the google scripts and defined all the adslots for the whole website (you will get it with the "generate tags").
On each page: you put the <body> part of the script like you would do anywhere else.
With this, you will be able to get a new ad served each time you load a new page. However, if you browse between pages, you will never get them to refresh.
To make for this, you can use googletag.pubads().refresh(). However, you want to only refresh the slots that are in the page that you are loading, otherwise you break some terms and conditions. Plus, you cannot refresh slots that have not been displayed yet, so it will fail if you defined slots for the whole website but all the pages have not been loaded yet, which is quite likely.
But you can pass the slots that are in the current page to the refresh() function. Here is how I did it:
function refreshAds() {
// Get all the slots
var allSlots = googletag.pubads().getSlots();
var slotsToRefresh = Array();
// Select the slots that are on the current page based on their dom Id
for (var i=0; i<allslots.length; ++i)
if (isSlotIdOnTheCurrentPage(allSlots[i].getSlotId().getDomId()))
slotsToRefresh.push(allSlots[i]); // I let you implement the logic behind naming ids slots and divs
if (slotsToRefresh.length > 0)
googletag.pubads().refresh(slotsToRefresh);
}
$(document).on("pagechange", function() {refreshAds();})
There you go, each time you go back to a page, the slots are refreshed, each time you go to a new page, a new slot is created (provided that it was defined in the <head>).
I hope it will help! There might be a way to get it to work seamlessly in Adsense but I did not try.
Maybe using jQuery's getScript() method would help in this situation. I propose that you try to include this inside a pageinit function. Let me give you a brief example.
$(document).delegate('[data-role=page]','pageinit',function(){ // this would get executed on page init of every JQM page
$.getScript('path/to/yourlib.js',function(){ // using getScript should help you be able to load scripts since the head doesn't get loaded again
Demo(); //This would be code that your lib uses
});
});

Displaying Google results in a frame

Some time in the last year, a tool that I use no longer displays Google search results in one of its frames. I suspect that Google started using JavaScript code to hide itself, if it is being displayed in a frame, which is understandable for most uses.
However, this is a tool that only I use, so I'm not misrepresenting to anyone. I use this tool to research data. One frame has a form where I enter data that I find online. The other frame has the Google results and the pages they link to. I can see both the data form that I'm working on and the changing search/results side-by-side in one window.
I tried going to an older browser version, but I think they are using JavaScript.
Now I have to right-mouse click "open in a new tab" and then click to the new tab, and then close it, a lot of extra overhead when I'm trying to process this repetitive research over and over.
Any ideas? Confirmations as to what has changed? I suppose I could retrieve the page in PHP, strip out the part that hides the page and then put the page source in the other frame. A bit of a challenge for me.

Hard refreshes and SEO

I couldn't find an answer to this on the web. I have a site, where I try to avoid hard refreshes as much as possible. It's a sequences of photos, and upon a user click of a central div, a little page (a RoR partial) loads within that div with a new photo in it.
The user keeps clicking, the photo keeps changing, and the URL of the page never changes. The title of the photo does change though. And so I want the web crawlers to see this...
Is there any advantage to having a hard refresh or not in this scenario? Will the Web Crawlers see the title of the photo in the div, and index my home page? Or at least the url of the inner div?
I hope this makes sense! Thanks!
It all depends on what you mean by a hard refresh. If all of the pictures, and their related data (title etc.) are loaded when the page first loads, and the click is just a javascript event that changes the css a bit to display the next picture then that has no negative effect on SEO. If clicking that link makes an ajax request back to your server to retrieve the image, then it will never get picked up by the search engine web crawler, and will not contribute to SEO.
If you aren't sure if this click is an ajax request, or just a css change, you can look at your html source to figure it out. If all your image tags are in your html source then it's not making an ajax request. If you only see one (or zero) then it is making an ajax request.
If the page title would never change, then there's no benefit. But if you're loading a new image, the page title should change for optimal SEO.
There's a workaround, though. Just make it to where you can access the images specifically with a static page and make sure Google spiders it. You can keep the normal page flow as-is using this method.
Edit: I should add that I had a site that got 60% of it's traffic from Google Image searches, so I'd say you'd definitely want them indexed separately.

Linking to a specific section of a page from Google custom search engine result

I would like to know if there is a way when using Google custom search engine to have Google CSE link to a page with a URL like this
http://www.mysite.com/mysection/mysectionarticles.html#myarticle234
or something close to that.
Let’s say Google would find the searched words in a certain part of the page it could be in a or after an anchor or something like that and would supply in the search result a way to link to this specific section of the page.
So if you have big pages the user wouldn't have to scroll through the page to find the relevant part he saw in the CSE snippet.
It could also be used if you have a dynamic page that change state using JavaScript. Part of the page is hidden to the user until he does an action in the pages, but this hidden content was indexed by Google because it’s part of the page. So when the user clicks on the link in the search result he ends up on a page and can’t find the relevant part because it’s hidden.
Take a look at Google's support for structured/rich data and ajax urls for crawling (aka hash-bangs). One or both of them ought give you access to the pages with the right things displayed.

Resources