What methods do Google and Yahoo use to update the URL displayed in the browser's status bar?

Have you ever noticed that on Google and Yahoo search pages, the URLs of the search result links actually point to google.com or yahoo.com? It's a clever trick they use by adding extra arguments to the URLs that allow for redirection to the actual search result when clicked. This way, the user sees the search result URL in their browser's status bar instead of the google.com or yahoo.com URL.

I've always been curious about how they achieve this.

In the past, setting the window.status property with JavaScript would have been the solution, but unfortunately, that method doesn't seem to work anymore as explained in Reliable cross browser way of setting Status bar text

For example, I tried using a link like this:

<a href="http://somedomain.com/ReallyLongURLThatShouldNotBeSeenInTheStatusBar"  onmouseover="window.status='http://niceShourtUrl.com/'" onmouseout="window.status=''">Click Me</a>

However, the window.status strategy does not work for achieving the same effect as seen on Google's and Yahoo's search results pages. What can be done to fix this link so that it behaves like those links? Ideally, when a user hovers over the link, "" should be displayed in the status bar.

Answer №1

Deciphering the content may be a challenge, but upon closer examination, you'll notice that the URLs within the <a> tags are indeed the accurate destination URLs. This explains why the browser's status bar reflects the correct URL instead of the tracking link it redirects you through after clicking. Additionally, there exists a piece of onclick JavaScript code designed to intercept clicks before the default action of the browser (following the link) occurs.

Answer №2

Google has implemented a clever method to track user clicks by changing the destination of links using onMouseDown handlers. This means that when a user clicks on a link, the link is initially directed towards Google before being redirected elsewhere after an onClick event.

Here's how it works:

Step 1. User clicks on a link (mouse button is down)

Step 2. onMouseDown event triggers

Step 3. Link target (href value) is altered

Step 4. Mouse button is released

Step 5. onClick event triggers

Step 6. Browser recognizes the click and redirects the user to the modified destination

Step 7. The browser opens a Google redirect page, sending the user to the original intended destination

In the past, Google tracked clicks using only the onMouseDown event without altering the link destination. However, this method was not as reliable, leading Google to adopt the current technique of link alteration for more accurate tracking.

Answer №3

From what I have observed, it seems that the complete link is embedded within the 'href' attribute of the displayed link. However, they employ a JavaScript function to intercept the 'onclick' event, which subsequently directs you through their website upon clicking the link.

Answer №4

As an illustration, the link to StackOverflow appears as follows:

<a onmousedown="return clk(this.href,'','','res','1','','0CBwQFjAA')" class="l" href="http://stackoverflow.com/"><em>Stack Overflow</em></a>

The click function is embedded within the compressed source code. Here is the code with some added spaces for readability:

window.clk = function ( e, f, g, k, l, b, m )
{
    if ( document.images )
    {
        var a = encodeURIComponent || escape,
            c = new Image,
            h = window.google.cri++;

        window.google.crm[h] = c;
        c.onerror = c.onload = c.onabort = function()
        {
            delete window.google.crm[h]
        };

        var d, i, j;

        if ( google.v6 )
        {
            d = google.v6.src;
            i = google.v6.complete || google.v6s ? 2 : 1;
            j = (new Date).getTime() - google.v6t; delete google.v6
        }

        if ( b != "" && b.substring( 0, 6 ) != "&sig2=" )
            b = "&sig2=" + b;

        c.src = [
                "/url?sa=T",
                "&source=" + google.sn,
                f ? "&oi=" + a(f) : "",
                g ? "&cad=" + a(g) : "",
                "&ct=",
                a( k || "res" ),
                "&cd=",
                a( l ),
                "&ved=",
                a( m ),
                e ? "&url=" + a( e.replace( /#.*/, "" ) ).replace( /\+/g, "%2B" ) : "",
                "&ei=",
                google.kEI,
                d ? "&v6u=" + a( d ) + "&v6s=" + i + "&v6t=" + j : "",
                b ].join( "" )
    }
    return true
 };

Without delving too deeply into it, the key concept here is that it generates a Google URL and assigns it to this.href (the link's target) when you click the link. Subsequently, the altered URL is processed by the browser, redirecting you to the modified destination while displaying the initial link address.

Answer №5

The process consists of multiple steps. When dealing with an <a> tag, the href attribute in the HTML points to the actual page, ensuring that browsers without JavaScript can navigate to the intended destination.

Additionally, a mousedown event handler is attached to the link. This event triggers when a mouse button is pressed while hovering over the link, regardless of which mouse button is used. The handler replaces the href with a redirecting script within the search engine's domain.

By implementing this method, the correct URL is displayed until the last moment before redirection, allowing for the use of a redirecting hit logger even when opening the link in a new tab.

Answer №6

Instead of following your example, it seems like they're doing the complete opposite. They've included the href attribute with "the link" and are using the onclick event for tracking purposes.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When a row is clicked, retrieve the data specific to that row

I have implemented a data-grid using react-table where I pass necessary props to a separate component for rendering the grid. My issue is that when I click on a particular row, I am unable to retrieve the information related to that row using getTrProps. ...

Utilizing GraphicsMagick with Node.js to Extract Page Frames from Multi-Page TIF Files

I am currently working with a JavaScript script that can successfully convert a single page TIF file to JPEG. However, I am facing difficulties in determining whether "GraphicsMagick For Node" (https://github.com/aheckmann/gm) has the capability to extra ...

Enhancing React Native experience by dynamically editing array elements

This code block defines the state of my program, including an array: this.state = { arr: [{ arrid: 0, arrEmail: '', arrName: '', arrPhone: '' }], id: 0, email: "", isChecked: true, name: "", phon ...

Just encountered an issue stating "PrismaClient cannot run in the browser" while working with [Next.js]

My initial plan was to log all the IDs of news in my database using console. However, when I executed the code, an error occurred as shown in this image. What is the best way to address and resolve this issue? https://i.stack.imgur.com/ci8G1.png ...

What is the proper method for terminating an Express app.all?

Here's a snippet of my code where I utilize the app.all method. In this scenario, I am invoking the fetchBuildings function based on the building ID or hash provided in the URL. Subsequently, I am assigning values to the title, description, and image ...

What is the reason behind allowing JavaScript to perform mathematical operations with a string type number?

let firstNum = 10; let secondNum = "10"; console.log(firstNum * secondNum); // Result: 100 console.log(secondNum * secondNum); // Result: 100 ...

Tips for retrieving multiple data outputs from an ajax success function

Within my project, I have two separate JavaScript files named myJs1.js and myJs2.js. One of the methods in myJs1.js is invoking a method from myJs2.js. My goal is to retrieve the values r1 and r2 into the results (within myJs1.js). I attempted to achiev ...

Guide to importing Bootstrap 5 bundle js using npm

Having some issues with implementing Bootstrap5 and NPM. The website design is using bootstrap, which works fine, but not all the JavaScript components (dropdowns, modals, etc). I want to figure out how to import the Bootstrap JS bundle without relying on ...

URLs not being gathered by the web scraping tool

Currently involved in scraping data from this specific website to compile a database. Previously, I had functioning Python code available on GitHub that successfully accomplished this task. However, due to a major overhaul in the HTML structure of the site ...

Modify content or display picture within accordion panel based on its identifier

In my view, I have a model representing a list of items. Each item has a unique ID, which is included in the H2 header tag. The details of each item are displayed in a div below the header. Initially, there is an image within the header that is set to disp ...

What is the process of transforming a string into an angular binding?

I have a variable called message that contains the text "you are moving to {{output.number}}". I attempted to insert this into a div element using $("#message").html(message); However, it just displayed the entire string without replacing {{output.number ...

Retrieve JSON object by matching another JSON property

I am working with an array of id's and their respective contents in a JSON response. My goal is to retrieve the content based on the received id. For instance, if the ID is 1 (returned from the JSON), I aim to access the JSON data using "data.id" (wh ...

Enhancing Functional Components with Idle Timeout using React Hooks

I am currently working on an application that requires implementing an idle timeout feature. This feature should first notify the user that they will be logged out in one minute, and then proceed to log them out after the time has expired. Previously, I s ...

Removing an element from an array in a Laravel database using AngularJS

I am currently working on a project where I need to delete an item from my Laravel database, which is a simple Todo-List application. To achieve this, I have implemented a TodosController in my main.js file using AngularJS and created a Rest API to connect ...

Is there a way to invoke an Angular2 function from within a Google Map infowindow?

I am currently working on integrating Google Maps using javascript in a project, and I'm facing a challenge. I want to call an Angular2 function inside an infowindow as shown in the code snippet below. Pay attention to the infoContent variable that co ...

Converting Buffers to Binary with JavaScript Node.js

I've been working with Node.JS Buffers to send and receive packets, but I'm struggling to figure out how to convert these buffers into binary representation. I attempted the following code snippet, but it didn't yield the expected results co ...

When using promises in Vue, you can expect to receive an observer object

In my Vue.js project, I am trying to trigger a Vuex action in the created() lifecycle hook and then proceed to call an asynchronous method to fetch more data from the server upon receiving the initial data. The goal is to utilize this data in a component ...

Is there a way to ensure a function is only executed once whenever the page is refreshed?

I have the following code snippet: function myfunc () { alert('executed'); } $('.classname').on('click' function () { myfunc(); }); I am trying to ensure that myfunc is only executed once. I don't want it to ru ...

What is the best way to scale down my entire webpage to 65%?

Everything looks great on my 1920x1080 monitor, but when I switch to a 1024x768 monitor, the content on my webpage becomes too large. I've been manually resizing with CTRL+Scroll to reduce it to 65%, which works fine. Is there a code solution using CS ...

Setting the state based on Promise values within a loop

I am currently facing a challenge in my React project where I am using axios to interact with an external API. The goal is to loop through the array of objects retrieved from the API call and utilize the values returned by a separate function within the ...