Redirection Javascript via SRC

S

Steph

Bonjour,

Je souhaite lancer une redirection vers un fichier php via SRC= dans une
condition if (voir ci-dessous en bas du script) mais la redirection ne
fonctionne pas. Par contre la condition est bien validée car le cookie (crée
précédemment) est bien effacé par SetCookie.
Pourriez-vous me dire ce qui ne va pas ?

Merci d'avance
Steph

<SCRIPT language="javascript" type="text/javascript">
var pathname=location.pathname;
var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var date_exp = new Date();
var date_del = new Date();
date_exp.setTime(date_exp.getTime()+(3600*1000)); // cookie de 1
heure
date_del.setTime(date_del.getTime()-(365*24*3600*1000)); // Tuer le cookie

function SetCookie (name, value) {
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=name+"="+escape(value)+
((expires==null) ? "" : (";
expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1)
endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen) {
var j=i+alen;
if (document.cookie.substring(i, j)==arg)
return getCookieVal (j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;}
return null;
}


// CHECK IF INDEX VALUE SET
var index=GetCookie("Index");
if (index!="") {
src=http://www.siteweb.com/fichier.php?partnerID=partner;
//DELETE COOKIE
SetCookie("Index","",date_del,myDomain);
}

</SCRIPT>
 
S

Steph

Steph said:
Bonjour,

Je souhaite lancer une redirection vers un fichier php via SRC= dans une
condition if (voir ci-dessous en bas du script) mais la redirection ne
fonctionne pas. Par contre la condition est bien validée car le cookie
(crée précédemment) est bien effacé par SetCookie.
Pourriez-vous me dire ce qui ne va pas ?

Merci d'avance
Steph

<SCRIPT language="javascript" type="text/javascript">
var pathname=location.pathname;
var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var date_exp = new Date();
var date_del = new Date();
date_exp.setTime(date_exp.getTime()+(3600*1000)); // cookie de 1
heure
date_del.setTime(date_del.getTime()-(365*24*3600*1000)); // Tuer le cookie

function SetCookie (name, value) {
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=name+"="+escape(value)+
((expires==null) ? "" : (";
expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1)
endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen) {
var j=i+alen;
if (document.cookie.substring(i, j)==arg)
return getCookieVal (j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;}
return null;
}


// CHECK IF INDEX VALUE SET
var index=GetCookie("Index");
if (index!="") {
src=http://www.siteweb.com/fichier.php?partnerID=partner;
//DELETE COOKIE
SetCookie("Index","",date_del,myDomain);
}

</SCRIPT>
A la fin du script, il y a une petite erreur, partner = index.
 
W

web.dev

Steph said:
Bonjour,

Je souhaite lancer une redirection vers un fichier php via SRC= dans une
condition if (voir ci-dessous en bas du script) mais la redirection ne
fonctionne pas. Par contre la condition est bien validée car le cookie (crée
précédemment) est bien effacé par SetCookie.
Pourriez-vous me dire ce qui ne va pas ?

Merci d'avance
Steph

<SCRIPT language="javascript" type="text/javascript">
var pathname=location.pathname;
var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var date_exp = new Date();
var date_del = new Date();
date_exp.setTime(date_exp.getTime()+(3600*1000)); // cookie de 1
heure
date_del.setTime(date_del.getTime()-(365*24*3600*1000)); // Tuer le cookie

function SetCookie (name, value) {
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=name+"="+escape(value)+
((expires==null) ? "" : (";
expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1)
endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen) {
var j=i+alen;
if (document.cookie.substring(i, j)==arg)
return getCookieVal (j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;}
return null;
}


// CHECK IF INDEX VALUE SET
var index=GetCookie("Index");
if (index!="") {
src=http://www.siteweb.com/fichier.php?partnerID=partner;

I believe the problem is here. You should change it to:

window.location.href =
"http://www.siteweb.com/fichier.php?partnerID=partner";
 
S

Steph

"web.dev" <[email protected]> a écrit dans le message de (e-mail address removed)...
Bonjour,

Je souhaite lancer une redirection vers un fichier php via SRC= dans une
condition if (voir ci-dessous en bas du script) mais la redirection ne
fonctionne pas. Par contre la condition est bien validée car le cookie
(crée
précédemment) est bien effacé par SetCookie.
Pourriez-vous me dire ce qui ne va pas ?

Merci d'avance
Steph

<SCRIPT language="javascript" type="text/javascript">
var pathname=location.pathname;
var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var date_exp = new Date();
var date_del = new Date();
date_exp.setTime(date_exp.getTime()+(3600*1000)); // cookie de 1
heure
date_del.setTime(date_del.getTime()-(365*24*3600*1000)); // Tuer le cookie

function SetCookie (name, value) {
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=name+"="+escape(value)+
((expires==null) ? "" : (";
expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1)
endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen) {
var j=i+alen;
if (document.cookie.substring(i, j)==arg)
return getCookieVal (j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;}
return null;
}


// CHECK IF INDEX VALUE SET
var index=GetCookie("Index");
if (index!="") {
src=http://www.siteweb.com/fichier.php?partnerID=partner;

I believe the problem is here. You should change it to:

window.location.href =
"http://www.siteweb.com/fichier.php?partnerID=partner";
//DELETE COOKIE
SetCookie("Index","",date_del,myDomain);
}

</SCRIPT>
Yes that's work fine !
Can you just tell me how i can pass the variable index to the php file.
Indeed with the 'http://www.siteweb.com/fichier.php?partnerID=index"; the
partnerID equal index but not equal to variable contained into index.

Many thanks
Steph
 
W

web.dev

Steph said:
"web.dev" <[email protected]> a écrit dans le message de (e-mail address removed)...
Bonjour,

Je souhaite lancer une redirection vers un fichier php via SRC= dans une
condition if (voir ci-dessous en bas du script) mais la redirection ne
fonctionne pas. Par contre la condition est bien validée car le cookie
(crée
précédemment) est bien effacé par SetCookie.
Pourriez-vous me dire ce qui ne va pas ?

Merci d'avance
Steph

<SCRIPT language="javascript" type="text/javascript">
var pathname=location.pathname;
var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var date_exp = new Date();
var date_del = new Date();
date_exp.setTime(date_exp.getTime()+(3600*1000)); // cookie de 1
heure
date_del.setTime(date_del.getTime()-(365*24*3600*1000)); // Tuer le cookie

function SetCookie (name, value) {
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=name+"="+escape(value)+
((expires==null) ? "" : (";
expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1)
endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen) {
var j=i+alen;
if (document.cookie.substring(i, j)==arg)
return getCookieVal (j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;}
return null;
}


// CHECK IF INDEX VALUE SET
var index=GetCookie("Index");
if (index!="") {
src=http://www.siteweb.com/fichier.php?partnerID=partner;

I believe the problem is here. You should change it to:

window.location.href =
"http://www.siteweb.com/fichier.php?partnerID=partner";
//DELETE COOKIE
SetCookie("Index","",date_del,myDomain);
}

</SCRIPT>
Yes that's work fine !
Can you just tell me how i can pass the variable index to the php file.
Indeed with the 'http://www.siteweb.com/fichier.php?partnerID=index"; the
partnerID equal index but not equal to variable contained into index.

Many thanks
Steph

If I understood correctly, then this is what you want:

window.location.href = "http://url" + index;

Hope this helps :)
 
S

Steph

"web.dev" <[email protected]> a écrit dans le message de (e-mail address removed)...
"web.dev" <[email protected]> a écrit dans le message de (e-mail address removed)...
Bonjour,

Je souhaite lancer une redirection vers un fichier php via SRC= dans une
condition if (voir ci-dessous en bas du script) mais la redirection ne
fonctionne pas. Par contre la condition est bien validée car le cookie
(crée
précédemment) est bien effacé par SetCookie.
Pourriez-vous me dire ce qui ne va pas ?

Merci d'avance
Steph

<SCRIPT language="javascript" type="text/javascript">
var pathname=location.pathname;
var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var date_exp = new Date();
var date_del = new Date();
date_exp.setTime(date_exp.getTime()+(3600*1000)); // cookie de 1
heure
date_del.setTime(date_del.getTime()-(365*24*3600*1000)); // Tuer le
cookie

function SetCookie (name, value) {
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=name+"="+escape(value)+
((expires==null) ? "" : (";
expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1)
endstr=document.cookie.length;
return unescape(document.cookie.substring(offset,
endstr));
}
function GetCookie (name) {
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen) {
var j=i+alen;
if (document.cookie.substring(i, j)==arg)
return getCookieVal (j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;}
return null;
}


// CHECK IF INDEX VALUE SET
var index=GetCookie("Index");
if (index!="") {
src=http://www.siteweb.com/fichier.php?partnerID=partner;

I believe the problem is here. You should change it to:

window.location.href =
"http://www.siteweb.com/fichier.php?partnerID=partner";
//DELETE COOKIE
SetCookie("Index","",date_del,myDomain);
}

</SCRIPT>
Yes that's work fine !
Can you just tell me how i can pass the variable index to the php file.
Indeed with the 'http://www.siteweb.com/fichier.php?partnerID=index"; the
partnerID equal index but not equal to variable contained into index.

Many thanks
Steph

If I understood correctly, then this is what you want:

window.location.href = "http://url" + index;

Hope this helps :)

Yes it works, thanks !
Last question (if you don't mind) : if i have more than one javascript
variable to pass with the URL to the php file like
http://url.php?partner1=$index1&partner2=$index2&partner3=$index3 what is
the exact synthax to use with window.location.href ?
 
W

web.dev

Steph said:
"web.dev" <[email protected]> a écrit dans le message de (e-mail address removed)...
"web.dev" <[email protected]> a écrit dans le message de (e-mail address removed)...
Bonjour,

Je souhaite lancer une redirection vers un fichier php via SRC= dans une
condition if (voir ci-dessous en bas du script) mais la redirection ne
fonctionne pas. Par contre la condition est bien validée car le cookie
(crée
précédemment) est bien effacé par SetCookie.
Pourriez-vous me dire ce qui ne va pas ?

Merci d'avance
Steph

<SCRIPT language="javascript" type="text/javascript">
var pathname=location.pathname;
var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var date_exp = new Date();
var date_del = new Date();
date_exp.setTime(date_exp.getTime()+(3600*1000)); // cookie de1
heure
date_del.setTime(date_del.getTime()-(365*24*3600*1000)); // Tuer le
cookie

function SetCookie (name, value) {
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=name+"="+escape(value)+
((expires==null) ? "" : (";
expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1)
endstr=document.cookie.length;
return unescape(document.cookie.substring(offset,
endstr));
}
function GetCookie (name) {
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen) {
var j=i+alen;
if (document.cookie.substring(i, j)==arg)
return getCookieVal (j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;}
return null;
}


// CHECK IF INDEX VALUE SET
var index=GetCookie("Index");
if (index!="") {
src=http://www.siteweb.com/fichier.php?partnerID=partner;

I believe the problem is here. You should change it to:

window.location.href =
"http://www.siteweb.com/fichier.php?partnerID=partner";
//DELETE COOKIE
SetCookie("Index","",date_del,myDomain);
}

</SCRIPT>
Yes that's work fine !
Can you just tell me how i can pass the variable index to the php file.
Indeed with the 'http://www.siteweb.com/fichier.php?partnerID=index";the
partnerID equal index but not equal to variable contained into index.

Many thanks
Steph

If I understood correctly, then this is what you want:

window.location.href = "http://url" + index;

Hope this helps :)

Yes it works, thanks !
Last question (if you don't mind) : if i have more than one javascript
variable to pass with the URL to the php file like
http://url.php?partner1=$index1&partner2=$index2&partner3=$index3 what is
the exact synthax to use with window.location.href ?

In that case you would do something like this:

window.location.href = "http://url.php?partner1=" + index1 +
"&partner2=" + index2 + "&partner3=" + index3;
 
S

Steph

"web.dev" <[email protected]> a écrit dans le message de (e-mail address removed)...
"web.dev" <[email protected]> a écrit dans le message de (e-mail address removed)...
"web.dev" <[email protected]> a écrit dans le message de (e-mail address removed)...
Bonjour,

Je souhaite lancer une redirection vers un fichier php via SRC= dans
une
condition if (voir ci-dessous en bas du script) mais la redirection ne
fonctionne pas. Par contre la condition est bien validée car le cookie
(crée
précédemment) est bien effacé par SetCookie.
Pourriez-vous me dire ce qui ne va pas ?

Merci d'avance
Steph

<SCRIPT language="javascript" type="text/javascript">
var pathname=location.pathname;
var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var date_exp = new Date();
var date_del = new Date();
date_exp.setTime(date_exp.getTime()+(3600*1000)); // cookie de
1
heure
date_del.setTime(date_del.getTime()-(365*24*3600*1000)); // Tuer le
cookie

function SetCookie (name, value) {
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=name+"="+escape(value)+
((expires==null) ? "" : (";
expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1)
endstr=document.cookie.length;
return unescape(document.cookie.substring(offset,
endstr));
}
function GetCookie (name) {
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen) {
var j=i+alen;
if (document.cookie.substring(i, j)==arg)
return getCookieVal (j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;}
return null;
}


// CHECK IF INDEX VALUE SET
var index=GetCookie("Index");
if (index!="") {
src=http://www.siteweb.com/fichier.php?partnerID=partner;

I believe the problem is here. You should change it to:

window.location.href =
"http://www.siteweb.com/fichier.php?partnerID=partner";
//DELETE COOKIE
SetCookie("Index","",date_del,myDomain);
}

</SCRIPT>
Yes that's work fine !
Can you just tell me how i can pass the variable index to the php file.
Indeed with the 'http://www.siteweb.com/fichier.php?partnerID=index";
the
partnerID equal index but not equal to variable contained into index.

Many thanks
Steph

If I understood correctly, then this is what you want:

window.location.href = "http://url" + index;

Hope this helps :)

Yes it works, thanks !
Last question (if you don't mind) : if i have more than one javascript
variable to pass with the URL to the php file like
http://url.php?partner1=$index1&partner2=$index2&partner3=$index3 what is
the exact synthax to use with window.location.href ?

In that case you would do something like this:

window.location.href = "http://url.php?partner1=" + index1 +
"&partner2=" + index2 + "&partner3=" + index3;

Great !
Many thanks for your quick support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top