JS判断来路哪个搜索引擎来的并提示加入收藏

今天时代前端在网上闲逛时无意间发现的一个非常实用的JS代码,如果你通过搜索引擎访问该网站,则提示:您通过XX搜索引擎来到XX网站... 是否加入收藏夹?另外还有提示设置首页的功能。 友情提示:请自行修改代码中的时代前端网址。 实例代码: var sitename = "时代前端"; var siteurl = "http://www.52shidai.com/"; var referer = ''; var hellott='您好, 您...

今天时代前端在网上闲逛时无意间发现的一个非常实用的JS代码,如果你通过搜索引擎访问该网站,则提示:您通过XX搜索引擎来到XX网站… 是否加入收藏夹?另外还有提示设置首页的功能。

友情提示:请自行修改代码中的时代前端网址。

实例代码:

var sitename = “时代前端”;
var siteurl = “http://www.52shidai.com/“;

var referer = ”;
var hellott=’您好, 您从’;
var hellott1=’搜索关键字来到了 ‘+sitename+’ \n\n到访页面:’+location.href+’\n\n为了您方便访问,请点击确定将 ‘+sitename+’ 加入收藏夹’;

if(document.referrer.indexOf(“baidu”)!=-1)
{if(confirm( hellott + ‘ 百度 ‘ + hellott1 )){addfav();}}

if(document.referrer.indexOf(“google”)!=-1)
{if(confirm( hellott + ‘ 谷歌 ‘ + hellott1)){addfav();}}

if(document.referrer.indexOf(“sogou”)!=-1)
{if(confirm( hellott + ‘ 搜狗 ‘+ hellott1)){addfav();}}

if(document.referrer.indexOf(“soso”)!=-1)
{if(confirm( hellott + ‘ 腾讯SoSo ‘+ hellott1)){addfav();}}

if(document.referrer.indexOf(“yahoo”)!=-1)
{if(confirm( hellott + ‘ 雅虎 ‘+ hellott1)){addfav();}}

if(document.referrer.indexOf(“youdao”)!=-1)
{if(confirm( hellott + ‘ 网易有道 ‘+ hellott1)){addfav();}}

if(document.referrer.indexOf(“bing”)!=-1)
{if(confirm( hellott + ‘ 必应 ‘+ hellott1)){addfav();}}

function addfav()
{
window.external.AddFavorite(siteurl,sitename); //—加入收藏夹
//this.style.behavior=’url(#default#homepage)’; //this.setHomePage(siteurl); //—设为主页
}

使用方法:

请将以上代码复制到记事本中,另存为js_from.js,上传至网站根目录,然后将以下代码加入到网页的body与body之间。

<script type=”text/javascript” src=”/js_from.js”></script>

转载请注明文章转载自:网站前端,web前端,前端脚本,前端优化|时代前端 [http://www.52shidai.com]
本文链接地址:JS判断来路哪个搜索引擎来的并提示加入收藏

标签:, ,

才1个评论

  1. 上海网站建设 说:

    看起来不错,收藏了。

发表评论

*

* 绝不会泄露



Copyright © 网站前端,web前端,前端脚本,前端优化|时代前端 and WPYOU All Rights Reserved.

Powered by Wordpress and Theme by WPYOU