Expanding a hidden div by referring with an anchor from external page

前端 未结 3 1666
暖寄归人
暖寄归人 2021-01-22 12:02

I have a script which hides (display:none) certain divs in the list on page load. Div contents represents description of a book, and the whole list is some sort of bibliography.

3条回答
  •  误落风尘
    2021-01-22 12:34

    You can do something like this on the target page:

    window.onload = function() {
        var hash = window.location.hash; // would be "#div1" or something
        if(hash != "") {
            var id = hash.substr(1); // get rid of #
            document.getElementById(id).style.display = 'block';
        }
    };
    

    Essentially, you check on the page load whether the window's href has a hash attached to it. If it does, you find the

    and change the style display to block.

提交回复
热议问题