Javascript #在加载页面上的URL后自动出现

Javascript #在加载页面上的URL后自动出现,javascript,Javascript,如果访问该链接,页面加载后将显示尾随/# 这基本上是本脚本的一个问题: <script type="text/javascript" src="https://p14943.atraveo.com/index.php?controller=partnerintegration&action=default&width=1080&height=1000&lg=da&cur=DKK&versionname=Spanien_landingpage"

如果访问该链接,页面加载后将显示尾随/#

这基本上是本脚本的一个问题:

<script type="text/javascript" src="https://p14943.atraveo.com/index.php?controller=partnerintegration&action=default&width=1080&height=1000&lg=da&cur=DKK&versionname=Spanien_landingpage"></script>
源代码的脚本:

<script type="text/javascript">
window.addEventListener("message", function(a) {
    if (!("website" !== a.origin.substr(a.origin.length - 7) && ".atraveo.com" !== a.origin.substr(a.origin.length - 12) && ".atraveo.de" !== a.origin.substr(a.origin.length - 11) && ".atraveo-test.de" !== a.origin.substr(a.origin.length - 16)))
        if ("scrollUp" == a.data) window.location.hash = "atraveo", window.location.hash = "";
        else if ("scrollToFrame" == a.data) {
        if (a = document.getElementById(atraveoFrameId)) a = a.offsetTop, document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop =
            a : document.body.scrollTop = a
    } else document.getElementById(atraveoFrameId).style.height = a.data + "px"
}, !1);
</script>
如果我加上:

window.location.href.replace('#', '');
有了线,问题就解决了

但是,由于我对第三方网站没有控制权,我想知道我这边是否可以做些什么

try {
    //check wether it's working + initial cleanup
    history.replaceState( history.state, document.title, location.href.replace(/#$/,"") );

    //if the code didn't throw yet, add the event-listener
    addEventListener("hashchange", function(){
        var href = location.href, regex = /#$/;
        if(regex.test(href)) 
            history.replaceState( history.state, document.title, href.replace(regex, "") );
    }, false);
}catch(err){}
历史操作在某些浏览器中可能不可用,这就是为什么我将代码包装在try-catch块中并触发
history.replaceState()


另一方面,如果此代码在较旧的浏览器中失败,则后面的
#
可能没有吸引力,但这并不是需要不惜任何代价修复的关键问题。

不清楚您可以控制什么。你能不能修改那一行?第三方网站是什么意思?你的“问题”是什么还不清楚。@charlietfl,我仅有的脚本是我的附属网站提供给我的:为什么散列如此令人担忧?页面刷新是否正常?它以某种方式工作,但我不希望看到标签出现然后消失。请在atraveo脚本之前插入此片段,甚至可以在标题或正文顶部插入。它没有任何依赖关系,因此您不必等待任何库被加载。这个脚本应该没有明显的延迟;实际上,如果您手动更改哈希,您不会看到任何延迟。将脚本放入并不能解决问题,仍然会显示哈希,然后消失。“实际上,如果您手动更改哈希值,您不会看到任何延迟。”---这是什么意思?
window.location.href.replace('#', '');
try {
    //check wether it's working + initial cleanup
    history.replaceState( history.state, document.title, location.href.replace(/#$/,"") );

    //if the code didn't throw yet, add the event-listener
    addEventListener("hashchange", function(){
        var href = location.href, regex = /#$/;
        if(regex.test(href)) 
            history.replaceState( history.state, document.title, href.replace(regex, "") );
    }, false);
}catch(err){}