79820964

Date: 2025-11-15 17:02:42
Score: 3
Natty:
Report link

There is apparently no way to know which page is open by a particular user.
As someone said on a forum

How would the server know if HTML code is "opened" in a browser?

I couldn't find a solution, so I chose to do it differently.
All the code for SignalR is placed in the Layout.

Upon receiving a message, I want to know if the recipient is currently checking their messages or not.
I create a condition with an element of the document that only exists on the messaging page.

connection.on("ReceiveMessage", function(userexp, userdest, topic, message, refresh_status) {
   var contf = document.querySelector(".fiche"); // fiche only exists on my "Messaging" page
     if(contf != null)
      {
         //code for the Messaging page
      }
      else
      {
        //code for any other page (Notification PopUp in main menu)
      }

Consequently, by also placing the notification message template in the _Layout, I can notify the user at any time and anywhere on the site.

Reasons:
  • Blacklisted phrase (1): I want to know
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: AMP59