I am trying to set cookie to domain same as src of js file.
Scenario: In www.xyz html, I have included js file from qwe as below
<script type="application/javascript" src=".js"></script>
I am trying to set cookie to domain same as src of js file.
Scenario: In www.xyz. html, I have included js file from qwe. as below
<script type="application/javascript" src="http://qwe./b.js"></script>
From this b.js, i want to create cookie with domain set to .qwe.. I am setting cookie with following function
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+";domain=.qwe."+"; path=/;";
}
With above code I am unable to set cookie. Example: www.flipkart.-> Check cookies in resources tab of developer console-> .scorecardresearch. and .doubleclick are able to set cookie
I want to do same. Can someone please share solution for this? Real working solution. I have tried multiple solutions by doing Google search. It didn't work.
Share Improve this question edited Jun 26, 2015 at 17:26 User19380 asked Jun 26, 2015 at 13:35 User19380User19380 731 gold badge1 silver badge5 bronze badges1 Answer
Reset to default 11Client side JavaScript can set cookies only for the domain the webpage is hosted on.
The examples you cite use HTTP headers to set cookies, not JavaScript.