[英]Link from other site should open the first link of the site
看看下面的网站,将在以后删除: -
[职业页] [1]
在这个页面上,如果我来自Facebook / Linked等其他网站,它应该是这样的: -
![图片1] [2]
如果我从同一个网站访问,它应该如下: -
这是我的JS代码。 请建议做什么: -
function pageLoad() {
$("#careerdiv").accordion({
collapsible: true,
autoHeight: false,
active: false
});
$("a#various15").fancybox({
'width': 720,
'height': 390,
'autoScale': false,
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'type': 'iframe',
'speedIn': 600,
'speedOut': 400,
'overlayShow': true,
'overlayOpacity': 0.8,
'overlayColor': '#000',
'padding': '0px',
'onComplete': function () { $('.closer').click(function () { parent.$.fancybox.close(); }) }
});
}
请建议做什么
if (document.referrer.indexOf('facebook.com') > -1) {
// do something for visitors from facebook here
}
您可以使用document.referrer
。 这是一个人为的例子:
$(document).ready(function() { var referrer = document.referrer; if(referrer.match(/stackoverflow.com/i)){ // change this to the name of your site $('#targetDiv').show(); // change this line as needed for you actual page } else{ $('#targetDiv2').show(); // remove this line for you actual page // $('.ui-accordion-header').eq(0).click(); // uncomment this line for your actual page } });
.none{ display:none; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="targetDiv" class="none">You see this, so you came from SO</div> <div id="targetDiv2" class="none">You see this, so you came from a site other than SO</div>
你只需要检查引用者是否来自fb || 李和开放手风琴1号我猜:
if( document.referer ){
$("#careerdiv").accordion({
collapsible: true,
autoHeight: false,
active: 1
} else {
$("#careerdiv").accordion({
collapsible: true,
autoHeight: false,
active: false
});
}
您能否更改以下代码:
$("#careerdiv").accordion({
collapsible: true,
autoHeight: false,
active: false
});
以下(从这里获取主机检查):
if( document.referrer.indexOf(location.protocol + "//" + location.host) === 0){
$("#careerdiv").accordion({
collapsible: true,
autoHeight: false,
active: false
});
} else{
$("#careerdiv").accordion({
collapsible: true,
autoHeight: false,
active: 0
});
}
检查引用者是否是你自己的主机并激活第一个具有索引0
手风琴(基于零的索引)。 记得在服务器上测试它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.