Google 和 Yahoo 如何替换浏览器状态栏中的 URL?

发布于 2024-09-01 16:01:52 字数 708 浏览 1 评论 0原文

在Google和Yahoo搜索页面上,10个搜索结果链接的URL实际上指向google.com或yahoo.com。 URL 具有额外的参数,允许 google.com 或 yahoo.com 在单击链接时重定向到实际搜索结果。当用户将鼠标悬停在链接上时,搜索结果 URL(而不是 google.com 或 yahoo.com URL)将显示在浏览器的状态栏中。

我想知道他们是怎么做到的。

许多年前,这可以通过一些设置 window.status 的 javascript 来完成,但这似乎不再起作用,正如 设置状态栏文本的可靠跨浏览器方式

我有一个如下所示的链接: Click Me

此链接尝试使用 window.status 策略,但不起作用。如何修复此链接,使其与 Google 和 Yahoo 搜索结果页上的链接一样?在此示例中,我希望当用户将鼠标悬停在链接上。

On the Google and Yahoo search pages, the URLs of the 10 search result links actually point to google.com or yahoo.com. The URLs have extra arguments that allow google.com or yahoo.com to redirect to the actual search result when the link is clicked. When the user mouses over the link, the search result URL (and not the google.com or yahoo.com URL) is displayed in the browser's status bar.

I'm wondering how they do that.

Many years ago, this would have been accomplished by having some javascript that sets window.status, but that doesn't seem to work anymore, as is explained by Reliable cross browser way of setting Status bar text

I have a link that looks like this:
<a href="http://somedomain.com/ReallyLongURLThatShouldNotBeSeenInTheStatusBar" onmouseover="window.status='http://niceShourtUrl.com/'" onmouseout="window.status=''">Click Me</a>

This link tried to use the window.status strategy, but it doesn't work. How do I fix this link so that it acts like the links on Google's and Yahoo's search result pages? In this example, I want "http://niceShourtUrl.com/" to be displayed in the status bar when the user mouses over the link.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

呆橘 2024-09-08 16:01:52

It's hard to read the source, but you will see that in fact the URLs (in the <a> tags) are the correct destination URLs, which is why the browser's status bar shows the correct URL (instead of the tracking link that it redirects you through when you actually click). There is then some onclick JavaScript that can then intercept the clicks before the browser's default action (following the link) can take place.

梦行七里 2024-09-08 16:01:52

Google 在每个链接上都有 onMouseDown 处理程序,可将链接从原始源更改为指向 Google 重定向。因此 onmousedown 替换了链接,当 onClick 出现时(onmousedown 之后不久),链接已经指向原始方向之外的其他位置。

步骤 1. 用户单击链接(鼠标按钮按下)

步骤 2. onMouseDown 事件触发

步骤 3. 链接目标(href 值)更改

步骤 4. 鼠标按钮出现

步骤 5. onClick 事件触发

步骤 6. 浏览器看到单击链接并将用户转发到所需的目的地(由已更改的 href 值设置)

步骤 7. 浏览器打开 Google 重定向页面,这会将用户转发到原始目的地

更新:Google 用于跟踪 onmousedown 上的点击仅事件,并没有改变链接目的地。当在链接上按下鼠标按钮时,会向 google 服务器发出图像加载请求,该服务器会计算点击次数 (onmousedown => new Image("coogle.counter.server.com/link=www.pressed.com" )) 但我猜它被误用了或者不够可靠,所以他们决定使用当前的链接更改技术。

Google has onMouseDown handlers on every link that change the link from the original source pointing towards Google redirect. So onmousedown replaces the link and when onClick appears (shortly after the onmousedown) the link is pointing already to somewhere else than the original direction.

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

Step 2. onMouseDown event triggers

Step 3. link target (a href value) is altered

Step 4. Mouse button comes up

Step 5. onClick event triggers

Step 6. Browser sees that a link was clicked and forwards the user to the desired destination (set by an already altered href value)

Step 7. Browser opens a Google redirect page and this forwards the user to the original destination

Updated: Google used to track clicks on an onmousedown event only and didn't alter the link destination. When a mouse button was pressed on a link an image loading request was made towards google servers which counted the click (onmousedown => new Image("coogle.counter.server.com/link=www.pressed.com")) but I guess it was misused or it wasn't reliable enough that they decided to use the current link altering technique.

冷清清 2024-09-08 16:01:52

我认为他们实际上在链接的 href 中有完整的链接。但他们使用 JavaScript 来捕获 onclick,然后当您单击该链接时,它会通过他们的网站进行路由。

I think they actually have the full link in the href of the link. BUT they use javascript to catch the onclick and then when you click the link, it routes through their site.

心在旅行 2024-09-08 16:01:52

例如,StackOverflow 的链接实际上看起来像这样:

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

现在,单击函数位于最小化源代码内部的某个位置。这里的代码带有一些额外的空格:

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
 };

无需真正详细查看它,它的重要思想是它计算一些 google url,并设置 this.href (= 链接的链接目标! ) 当您单击链接时指向该新网址。之后,将对链接进行评估,浏览器会将您发送到更改后的 url,尽管之前显示的是原始链接 url。

For example the link to StackOverflow looks actually like this:

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

Now the click function is somewhere inside that minimized source code. Here you have the code with some additional whitespace:

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 really looking at it in detail, the important idea about it is that it calculates some google url, and sets this.href (= the link's link target!) to that new url when you click the link. After that the link is then evaluated and the browser sends you to that changed url despite showing the original link url before.

滿滿的愛 2024-09-08 16:01:52

这是一个多部分的过程。对于给定的 标记,HTML 中的 href 属性将指向实际页面。这使得没有 JavaScript 的浏览器能够转到正确的位置。

接下来,链接上有一个 mousedown 事件处理程序。当您将鼠标悬停在链接上时按下鼠标按钮时,将触发 mousedown 事件。即使按下鼠标右键或中键,该事件也会触发。该处理程序将 href 替换为搜索引擎域中的重定向脚本。

这样,他们仍然会在最后可能的时刻显示正确的 URL,但他们仍然使用重定向命中记录器,即使您在新选项卡中打开链接也是如此。

It's a multipart process. For a given <a> tag, the href attribute in the HTML will point to the actual page. This allows browsers without JavaScript to go to the right place.

Next, there is a mousedown event handler on the link. The mousedown event fires when you depress a mouse button while hovering over the link. This event fires even if the right or middle mouse button is pressed. The handler replaces the href with the redirecting script in the search engine's domain.

That way they still display the correct URL up to the last possible moment, but they still use the redirecting hit logger, even when you open the link in a new tab.

农村范ル 2024-09-08 16:01:52

看来它们的做法与您在示例中的做法完全相反。他们有 href="the link" 和 onclick 事件作为跟踪功能。

It appears they do the direct opposite of what you have in your example. They have the href="the link" and the onclick event as the tracking function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文