带有 onload() 的错误,仅适用于测试警报

Bug with a onload(), works only for testing alert

我的功能有问题onload()。我在 body

开始加载
<body onload="myLoad();">

然后我做了一个脚本

<script>
    function myLoad() {
        alert("Test");
    }
</script>

它适用于这个版本。但是当我在脚本中添加更多内容时它停止工作了。

<script>
    function myLoad() {
        alert("Test");
        var URL == window.location.pathname;
        if (URL == "index.html#offers")
            {
                document.getElementById("autoiframe").src = "Kontakt.html";
            }
        }
</script>

我不明白为什么在第二个版本中警报停止工作(?)。当然测试 url 也不起作用。哪里出了问题?我应该改变什么? 先感谢您。 ;)

我想只需将 var URL == window.location.pathname; 替换为 var URL = window.location.pathname;

是的,我不得不更改它以及 .href 的 .pathname ^^

function myLoad() {
                    var URL = window.location.href;
                    alert(URL);
                        if (URL === "completly link")
                            {
                                document.getElementById("autoiframe").src = "link.html";

                    }}

感谢您的帮助。