How to use JavaScript to fill a form on another page

前端 未结 4 1519
猫巷女王i
猫巷女王i 2020-11-29 05:08

I am trying to fill out the fields on a form through JavaScript. The problem is I only know how to execute JavaScript on the current page so I cannot redirect to the form a

4条回答
  •  长情又很酷
    2020-11-29 05:39

    It is a good place to use cookies

    Ex: From quirksmode.org

    function createCookie(name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
    

    and a side note, you can use the onload event to know when the page is ready

    
    

提交回复
热议问题