How to make simple include script in html

1

I would like to know how I can make a simple script to make my login screen available to my clients.

  • 'Example' I have a simple form that logs into my system

          <form action="http://www.xx.com.br/logar.php">
          <input type="text" name="login">
          <input type="text" name="senha">
          <input type="submit" value="Logar">
          </form>
    

I wanted a simple way to make this form available for my clients to include in their sites an include type rather than running in simple html

    
asked by anonymous 05.07.2015 / 17:55

3 answers

3

Let's say that the domain with JavaScript with the login form is seusite.com .

Create a javascript file: seusite.com/formulario.js

function loginMeuSite() {
    var divLoginSite = document.getElementById("divLoginSite");
    divLoginSite.innerHTML = '<form action="http://www.xx.com.br/logar.php"><input type="text" name="login"><input type="text" name="senha"><input type="submit" value="Logar"></form>';
}
document.addEventListener("DOMContentLoaded", function(event) { loginMeuSite(); });

Ask your clients to insert the following javascript preferably between the <head></head> tags:

<script src="http://seusite.com/formulario.js"type="text/javascript"></script>

And ask to enter <div> of the login form in local where the login form should appear:

<div id="divLoginSite"></div>

Example

sitedocliente.com/cliente.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Incluindo JS</title>
    <link rel="stylesheet" href="">
    <script src="http://seusite.com/formulario.js"type="text/javascript">
</head>
<body>

    <table>
        <caption>Tabela 1</caption>
        <thead>
            <tr>
                <th>header</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>data</td>
            </tr>
        </tbody>
    </table>

    <div id="divLoginSite"></div>

</body>
</html>

    
05.07.2015 / 19:26
3

One way to do this, I suggest, can be through an iframe or by doing an embed via javascript.

The simplified way to do this is by joining iframe and embed, you would have to ask the client to put the code in the place you want to insert the content for you to do the insert of your url containing the form code, eg:

<script type='text/javascript' charset='utf-8'>     
   var iframe = document.createElement('iframe');       
   document.body.appendChild(iframe);

   iframe.src = 'url-do-formulário';       
   iframe.width = 'largura-do-formulário'; // em pixels
   iframe.height = 'altura-do-formulário'; // em pixels
</script>
    
05.07.2015 / 19:39
0

The simplest way you can do is to create a CNAME posting on your client's site for a particular page, when the client accesses his login page through a subdomain for example, the address will be to your system, without you need to distribute an iframe or something, which would generate more wear and tear with future maintenance.

Following is a sample DNS RECORD

NAME                 TYPE   VALUE
--------------------------------------------------
login.cliente.com.   CNAME  login.meusistema.com.
    
05.07.2015 / 18:53