Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
How to get PHP to change a JavaScript file to communicate with bookmarklet?

I'm trying to get PHP to change a JavaScript file. I want to have a form with a simple toggle switch and password like this:

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked + .slider {
  background-color: #2196F3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}
<!DOCTYPE html>
<html>
<head>


</head>
<body>
<form action = "something.php">
<input type = "password" placeholder = "Password..." name = "PASSWORD" id = "password"><br><br>
<label class="switch">
  <input type = "checkbox" name = "TOGGLE" id = "toggleSwitch">
  <span class="slider round"></span>
</label>
</form>

</body>
</html>

The form has a password and toggle switch. The PHP should validate the password, and if it is "1234", then if the toggle switch is checked, it will change the JavaScript file to "alert('ON');", if it is off, it will change to "alert('OFF');". There is a bookmarklet that will change functionality for what the form is at. The code is this

javascript:(function(){document.body.appendChild(document.createElement('script')).src='https://shimmering-raspy-roarer.glitch.me/script.js';})();

I'm not sure how to write this PHP. I am using glitch.com to make this website.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First of all you don't need to change the Javascript file. only thing you need is write a condition whenever it was true, then show the alert.

For example:

<!DOCTYPE html>
<html>
    <head></head>
    <body>
    <form>
        <input type = "password" placeholder = "Password..." name = "PASSWORD" id = "password"><br><br>
        <label class="switch">
            <input type = "checkbox" name = "TOGGLE" id = "toggleSwitch">
            <span class="slider round"></span>
        </label>
        <input type="submit">
    </form>
    
    <script>
        <!-- The alert code here -->
        <?php
        if ($_GET['PASSWORD'] == 1234) {
            $message = $_GET['TOGGLE'] ? 'ON' : 'OFF';
            
            echo "alert('$message');";
        }
        ?>
    </script>
    </body>
</html>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda