#ssield tag导致adsense问题

问题描述 投票:-1回答:1

我目前正在使用div id为用户访问我的网站并跳转到div(即sitename.com/sitepage/#div_1)。我的问题是,如果使用这些网址,adsense会将其识别为自动滚动,因此会以双击格式显示广告(即,用户必须点击两次才能转到广告客户网站,而不是正常点击一次)。

我不想使用scrollto脚本。但是,我发现popstate接近我想要的但是因为所有浏览器所需的效果都不一样,我想使用简单的东西:

setTimeout(function() {
  window.location.href = "#div1";
}, 1000);

以上将完成我期望的最终结果的第1步。但是,我有多个网址,例如

sitename.com/sitepage/#1
sitename.com/sitepage/#2
sitename.com/sitepage/#3

有没有办法认识到,如果url包含#than insert“div”到url和相应的数字,那么它与上面的代码相关联。我的希望如下:

setTimeout(function() {
    if(window.location.href.indexOf("#") > -1) {
      window.location.href = "#divn";
    }, 1000);

但我不知道怎么说“#”之后添加“div”

javascript jquery anchor adsense scrollto
1个回答
1
投票

编辑

这个应该工作的另一个想法!

问题是要阻止哈希动作滚动... 如果散列中的id不存在怎么办? 滚动不会发生,对吧?

尝试像domain/path/file#target99这样的东西,假设页面上不存在id #target99 ......但id #target确实如此。

99部分可以是任何东西......这是你想要的。这是你要删除的部分!

if(window.location.hash != null) {
  var hash = window.location.hash.replace("99","");  // Get the hash value WITHOUT the 99

  if(hash != "#"){  // in case of only "self"
    setTimeout(function() {
      $(hash).focus();
    }, 1000);
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.