How to make simple include script in html

Asked

Viewed 441 times

1

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

  • '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 type a include more that runs in simple html

3 answers

3


Let’s say the dominance with the 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 customers to enter the following javascript preferably between tags <head></head>:

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

And ask them to insert the <div> of the login form on local desired 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>

inserir a descrição da imagem aqui

  • 1

    Perfect solved my problem.....

3

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

The simplified way to do this, is by uniting 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, example:

<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>

  • IFRAME is already considered obsolete by many http://stackoverflow.com/questions/755795/are-iframes-html-obsolete

  • 2

    The answers most voted on the link you quoted say that this is nonsense. Iframe still exists and is valid, it just doesn’t need to be used in as many situations as before. But including content from an external site is typical usage to this day.

  • Of course it is still used today, as Adsense, etc, but I think javascript and other technologies that are compatible with virtually all mobiles have advanced so much that make other obsolete (iframe), but functional.

0

The simplest way that you can do is to create a CNAME note on your client’s website for a particular page, when the client accesses their login page through a subdomain for example, the note will be to your system, without you need to distribute an iframe or something, which would generate a greater wear with future maintenance.

Follow a DNS RECORD example

NAME                 TYPE   VALUE
--------------------------------------------------
login.cliente.com.   CNAME  login.meusistema.com.
  • In that case each client would include the form on their own, and change the action to the created record? That’s the idea?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.