Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display an HTML form via Javascript document.write?

If I am way off on how to employ this code then please forgive me, but is it possible to use something like

var url = 'http://www.maxcashtitleloans.com/lmapp.html'
document.write('<script src="'+url+'"></scr'+'ipt>')

to somehow display an html form inside many websites across different servers?

I have a single HTML form that will be continually updated as the needs of the company change, and would like to get them off of IFRAME calls.

A different questions towards the same goal "How can I display off site content on a website and not use IFRAME"

I know of an affiliate marketing company that uses

<script type='text/javascript'> 
    var inputOptions = { 
        UserID: '35696', 
        Product: 'payday', 
        ProductTemplate: 'lights', 
        Server: 'https://altohost.com/', 
        mobileDevices: true, 
        parseDefaultValue: true, 
        visitor: { 
            referrer: (document.cookie.match("rfrrr[\r\n\t ]*=[\r\n\t ]*(.*?)(;|$)") || [,''])[1],   
            subaccount: (document.cookie.match("src[\r\n\t ]*=[\r\n\t ]*(.*?)(;|$)") || [,''])[1], 
            keyword: (document.cookie.match("kwrd[\r\n\t ]*=[\r\n\t ]*(.*?)(;|$)") || [,''])[1], 
            clickid: (document.cookie.match("clcid[\r\n\t ]*=[\r\n\t ]*(.*?)(;|$)") || [,''])[1] 
        },     
    }; 
    document.write('<scr'+'ipt type="text/javascript" src="https://altohost.com/system/applicationforms/init.php?vn=inputOptions"></scr'+'ipt>'); 
</script> 
like image 320
user1789437 Avatar asked Oct 21 '22 09:10

user1789437


2 Answers

I'd propose a slightly different approach.

Use JavaScript to create the HTML form and include that script into all other websites using the same source.

Assume form.js is the file you want to include in every website.

Live DEMO

forms.js

var company = {};// Avoid name clashes!!!

company.form = function() {
    this.render();
};

company.form.prototype.render = function() {
    var url = "blablabla";
    this.form = document.createElement("form");
    this.form.setAttribute("method", "post");
    this.form.setAttribute("name", "company-specialform");
    this.form.setAttribute("action", url);

    var input = document.createElement("input");
    input.setAttribute("type", "text");
    input.setAttribute("value", "test");

    var submit = document.createElement("input");
    submit.setAttribute("type", "submit");
    submit.setAttribute("value", "submit");
    this.form.appendChild(input);
    this.form.appendChild(submit);
    var that = this;
    this.form.onsubmit = function(event) {
        that.submit.call(that, event);
    };
};

company.form.prototype.submit = function(event) {
    event.preventDefault(); // if needed
    alert(" Custom submit was called");
};

company.form.prototype.getForm = function() {
    return this.form;
};

company.form.append = function(container) {
    var form = new company.form();
    container.appendChild(form.getForm());
};

var target = document.getElementById("container");

company.form.append(target);

Now simply include forms.js on any other website, but make sure you use the same src for all of those websites, so you can keep the script up to date.

Now on every of those website, they can add the form with company.form.append(someDiv) and when you update the script the update will be available on all websites.

like image 70
flavian Avatar answered Oct 24 '22 04:10

flavian


Okay, there is solution for you. Your embed code like this;

<script>
var url = 'http://www.maxcashtitleloans.com/lmapp.js'
document.write('<script src="'+url+'"></scr'+'ipt>')
</script>

And http://www.maxcashtitleloans.com/lmapp.js like this :

function ajaxex()
{
var xmlhttp;
if (window.XMLHttpRequest){
    xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.write(xmlhttp.responseText);
}
}
xmlhttp.open("GET","lmapp.htm",true);
xmlhttp.send();
}
ajaxex();

Thats work fine. And demo for you : http://commention.com/lmappjsexample/ That solution like javascript proxy, you have to create a javascript file for render your html page.

like image 44
Cem Demir Avatar answered Oct 24 '22 04:10

Cem Demir