该部分是 foo.com/agriculture。它有一个与 javascript 中的名称相对应的横幅图像。我需要内部页面 foo.com/agriculture/harvest 有一个单独的横幅,而不是 foo.com/agriculture。我正在使用的用于每个页面的横幅交换的脚本如下:
<script type="text/javascript">
var dir = location.pathname.split("/")[1];
//var dir2 = location.pathname;
if (dir == "agriculture")
document.write('<IMG SRC="/images/ib_agriculture.jpg" WIDTH=1024 HEIGHT=91 BORDER=0>')
else if (dir == "showcase")
document.write('<IMG SRC="/images/ib_show.jpg" WIDTH=1024 HEIGHT=91 BORDER=0>')
else if (dir == "contact")
document.write('<IMG SRC="/images/ib_contact.jpg" WIDTH=1024 HEIGHT=91 BORDER=0>')
else if (dir == "distribution")
</script>
我尝试了以下不同的代码来尝试为内部页面 foo.com/agriculture/harvest 分配一个单独的横幅。
var dir = location.pathname.split("/")[1];
//var dir2 = location.pathname;
if (dir == "agriculture/harvest")
document.write('<IMG SRC="/images/ib_agriculture_harvest.jpg" WIDTH=1024 HEIGHT=91 BORDER=0>')
else if (dir == "showcase")
var dir = location.pathname.split("/")[1];
//var dir2 = location.pathname;
if (dir == "harvest")
document.write('<IMG SRC="/images/ib_agriculture_harvest.jpg" WIDTH=1024 HEIGHT=91 BORDER=0>')
else if (dir == "showcase")
上面的两个脚本继续抓取 foo.com/agriculture 横幅 (ib_agriculture.jpg) 而不是调用的 foo.com/agriculture/harvest (ib_agriculture_harvest.jpg)。我不确定如何让脚本每页调用适当的横幅。