How can I execute a script after calling [removed].href?

前端 未结 8 1453
执笔经年
执笔经年 2020-12-03 10:48

I have a script that redirects the user to another page. I want to load some content into a div on the new page after the new page has fully loaded. How can I do this. The f

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 11:02

    As pointed out in the other answers, you won't be able to perform any script instructions from your original site. Instead of using PHP to create the content statically, you could also use HTML fragments as arguments, e.g. like this:


    // in the original page:
    function goToPage() {
        window.location.href = 'http://www.mypage.com/info#my/url/path/with/content/to/load';
    }
    

    // in http://www.mypage.com/info:
    $( document ).ready(function () {
        if(window.location.hash)
            $('.my_class').load(window.location.hash.substring(1));
    }
    

提交回复
热议问题