11486 sujets

JavaScript, DOM et API Web HTML5

bonjour a tous
je me casse la tête depuis ce matin a vouloir remplacer

le contenu de window.location
par une simple variable php avec un lien

par exemple voici ce que je veux écrire dans window.location
$donnees["guid"]

et donc je souhaiterais tout simplement
remplacer ceci

window.location = "http://www.google.com/";


par

window.location = "<?php echo $donnees["guid"]; ?>";


voici le code complet que j'ai trouve et que je dois encore customiser
<html>
<head>
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("Leave tizag.com?")
if (answer){
alert("Bye bye!")
window.location = "http://www.google.com/";
}
else{
alert("Thanks for sticking around!")
}
}
//-->
</script>
</head>
<body>
<form>
<input type="button" onclick="confirmation()" value="Leave Tizag.com">
</form>
</body>
</html>
Modérateur
Bonjour,

A priori, tu as déjà tout ce qu'il faut.

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="description" content="Test">
<title>Test</title>
</head>
<body>
<h1>
<a href="https://forum.alsacreations.com/topic-5-89046-1.html">
 https://forum.alsacreations.com/topic-5-89046-1.html
 
</a>
</h1>
<input type="button" onclick="confirmation()" value="Leave Tizag.com">
<?php
	$donnees=array("guid"=>"http://www.google.com/");
?>
<script>
function confirmation()
{
	var answer=confirm("Leave tizag.com?");
	if (answer)
	{
		alert("Bye bye!");
		window.location="<?= $donnees["guid"]?>";
	}
	else
	{
		alert("Thanks for sticking around!");
	}
}
</script>
</body>
</html>

Amicalement,
bonjour
Merci pour l aide

c 'est super sympa et tout fonctionne a merveille

amicalement
Modifié par flexi2202 (09 Dec 2021 - 14:14)