How to include external form without iframe?

Member

by orpha , in category: Third Party Scripts , 2 months ago

How to include external form without iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by ryleigh , 2 months ago

@orpha 

One way to include an external form without using an iframe is to use JavaScript to make an AJAX request to the form's URL and then insert the HTML content of the form into your webpage dynamically. Here's a basic example of how you can do this:

  1. Create a DIV element in your HTML where you want the form to be displayed:
1
<div id="externalForm"></div>


  1. Use JavaScript to make an AJAX request to the form's URL and insert the form's HTML content into the DIV element:
1
2
3
4
5
6
7
8
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        document.getElementById("externalForm").innerHTML = this.responseText;
    }
};
xhttp.open("GET", "https://www.externalform.com/form.html", true);
xhttp.send();


  1. Make sure to replace "https://www.externalform.com/form.html" with the actual URL of the external form you want to include.


This code will fetch the HTML content of the external form and insert it into the DIV element with the ID "externalForm" on your webpage. This way, you can include the external form without using an iframe.