更新时间:2022-04-09 23:32:14
您可以将一个脚本元素注入到文档的HEAD中,使用一个回调函数来传递您需要的cookie,无论函数需要什么。
You could inject a script element into HEAD of the document with a callback that passes the cookie you need to whatever function needs it.
如下:
<script type="text/javascript">
var newfile=document.createElement('script');
newfile.setAttribute("type","text/javascript");
newfile.setAttribute("src", 'http://first.com/doAjax?getCookie&callback=passCookie');
document.getElementsByTagName("head")[0].appendChild(newfile);
</script>
并且页面first.com/doAjax?getCookie可以这样做:
And the page first.com/doAjax?getCookie could do this:
passCookie({'name':'mycookie', 'value':'myvalue'});