Javascript not working on Azure AD B2C custom signin

Sean Jolly 20 Reputation points
2023-07-01T10:47:02.0866667+00:00

I am trying to get javascript to run on an Azure AD B2C signin page, but it's not working and I'm not sure what I'm missing.

I'm using user flows with a custom signin page. To keep it as simple as possible, my custom page HTML is:

<!DOCTYPE html>
<html>
<head>
  <title>Login Page</title>
    <script>
    function displayText() {
      var welcomeText = document.getElementById('welcomeText');
        welcomeText.textContent = 'Welcome to the login page!';
    }
    </script> 

</head>
<body onload="displayText()">
    <p id="welcomeText"></p> 
    <div id="api"></div>
</body>
</html>

It is hosted in an Azure Blob Storage Container, and the custom page loads correctly when I test the signin, only the javascript doesn't seem to be working.

When I open the page from blob storage it works as expected:CwY4I

However when loading the sign in page the welcome text is missing:B2CPage

Things I have confirmed:

  1. Javascript is enabled in my browser
  2. Script is in the head tag
  3. Javascript is enabled:

JSEnabled

  1. I'm using version 2.1.12 of page layout (and have tried other versions with no luck):

PageLayout

Am I missing something that is stopping the javascript from running on the sign in page?

Microsoft Security Microsoft Entra Microsoft Entra ID
{count} votes

Accepted answer
  1. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2023-07-05T13:33:34.0066667+00:00

    Hi @Sean Jolly ,

    Thanks for reaching out.

    I tried to addAs a workaround, you can create a label and add Text to it.

    <!DOCTYPE html>
    <html>
    <head>
        <title>Login</title>
       <script>
    		var label = document.createElement('label');
             label.appendChild(document.createTextNode('Welcome to the Login page @')); 
             document.body.appendChild(label);
    	</script>
    </head>
    <body>
    <div id="api"></div>         
    </body>
    </html>
    
    
    

    which shows javacSript label on your customized page.

    User's image

    Hope this will help.

    Thanks,

    Shweta


    Please remember to "Accept Answer" if answer helped you.


1 additional answer

Sort by: Most helpful
  1. Hammed Abdulazeez 0 Reputation points MVP
    2025-03-14T11:11:21.43+00:00

    this is not working for me. the JS not even working at all

    not sure what is wrong

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.