1

Using JavaScript/jQuery within a web page, I need to load a different page into an iframe. I am doing it by finding the iframe using jQuery, and setting its src property, thus:

iframe.src = url;

Which works in that it displays the page in the iframe, but I need to attach a couple of cookies to that request to get the correct info on the page, and I can't figure out how to do that.

In the spirit of trial and error I tried inserting this line before the above code:

$.cookie("MyCookieName", "MyCookieValue");

but in Fiddler I see no cookie attached to the request. All the documentation I can find about cookies tells me how to generally get & set the values, but doesn't help explain what I'm doing wrong.

For what it's worth, the page that I'm loading into the iframe is in the same domain as the page hosting this JavaScript code.

How do I attach cookies to that query?

4

1 回答 1

2

如何将 cookie 附加到该查询?

您不能将 cookie “附加”到浏览器自己发出的简单 HTTP 请求。

值得一提的是,我加载到 iframe 中的页面与托管此 JavaScript 代码的页面位于同一域中。

然后以正常方式为该域设置 cookie - 一旦设置,浏览器将在自动请求 iframe URL 时发送它。

于 2013-03-19T15:26:45.397 回答