If statement 如何在<;b:如果blogger中有条件

If statement 如何在<;b:如果blogger中有条件,if-statement,conditional-statements,blogger,referrer,If Statement,Conditional Statements,Blogger,Referrer,我只想在来自特定主机名的流量出现时加载一些脚本 例如: 我将加载一个脚本时,博客流量从。我该怎么做?我试了很多,但还是找不到任何与之相关的东西 以下是我尝试过的一些代码 <b:if cond='"referrer" == "www.mywebsite2.com"'> <script>...</script> <b:else/> <script>...</scri

我只想在来自特定主机名的流量出现时加载一些脚本

例如: 我将加载一个脚本时,博客流量从。我该怎么做?我试了很多,但还是找不到任何与之相关的东西

以下是我尝试过的一些代码

<b:if cond='"referrer" == "www.mywebsite2.com"'>
     <script>...</script>
    <b:else/>
      <script>...</script>
    </b:if>

...
...

在这种情况下,我如何使用推荐人。

如果某个站点上的链接没有
rel=“noopener”
值,您可以检测该站点是否打开了链接

例如,您的站点域是
http://0.example.com
并且您的推荐人站点域是
http://1.example.com

在推荐人网站中,用户正在单击一个链接:

<a href="http://0.example.com" target="_blank">link</a>
要在该条件块下加载外部脚本,可以尝试AJAX或通用DOM插入:

方法1:

// Run the script for `http://1.example.com`
fetch('http://0.example.com/script.js').then(response => response.text()).then(text => {
    let script = document.createElement('script');
    script.textContent = text;
    document.head.appendChild(script);
    // Other script goes here ...
});
// Run the script for `http://1.example.com`
let script = document.createElement('script');
script.src = 'http://0.example.co./script.js';
document.head.appendChild(script);
script.addEventListener('load', e => {
    // Other script goes here ...
});
方法2:

// Run the script for `http://1.example.com`
fetch('http://0.example.com/script.js').then(response => response.text()).then(text => {
    let script = document.createElement('script');
    script.textContent = text;
    document.head.appendChild(script);
    // Other script goes here ...
});
// Run the script for `http://1.example.com`
let script = document.createElement('script');
script.src = 'http://0.example.co./script.js';
document.head.appendChild(script);
script.addEventListener('load', e => {
    // Other script goes here ...
});

谢谢你,它起作用了。但同样存在一个问题。如果我想加载一些外部的.js文件,那么如何使用If条件呢。