'how to pass a variable through url?

How can i pass a variable through url in javascript?

 const readMultipleNodesFromDatabase = (buyerId,sellerId) => {

    var buyer_id = buyerId;
    var seller_id = sellerId;
      var chatId = buyer_id + '_' + seller_id;
    firebase
      .database()
      .ref("Message/" + chatId)
      .once("value", function (snapshot) {
        // $fetchdata = snapshot.val();
        window.location.href = "<?php echo $module_site_url .'/add';?>";
      });
  };

How can i send the chatId through that url?



Solution 1:[1]

Not sure if I understand right but

window.location.href = `<?php echo $module_site_url .'/add';?>?chatid=${chatId}`

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pszaba