[英]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.