最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Display an HTML form via Javascript document.write? - Stack Overflow

programmeradmin3浏览0评论

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 = '.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 pany 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 pany that uses

<script type='text/javascript'> 
    var inputOptions = { 
        UserID: '35696', 
        Product: 'payday', 
        ProductTemplate: 'lights', 
        Server: '/', 
        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=".php?vn=inputOptions"></scr'+'ipt>'); 
</script> 

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./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 pany 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 pany that uses

<script type='text/javascript'> 
    var inputOptions = { 
        UserID: '35696', 
        Product: 'payday', 
        ProductTemplate: 'lights', 
        Server: 'https://altohost./', 
        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./system/applicationforms/init.php?vn=inputOptions"></scr'+'ipt>'); 
</script> 
Share Improve this question edited May 20, 2013 at 20:34 user1789437 asked May 20, 2013 at 20:28 user1789437user1789437 4681 gold badge8 silver badges22 bronze badges 7
  • 2 May be better to use PHP. – Mr. Polywhirl Commented May 20, 2013 at 20:31
  • 1 Do you control all the servers? – bfavaretto Commented May 20, 2013 at 20:31
  • 1 @Mr.Polywhirl and how PHP supposed to address that? – J0HN Commented May 20, 2013 at 20:31
  • 1 I control all servers, yes. I dont want google to see me connecting 900 websites. I know of a affiliate marketer that uses this code to acplish what Im trying to do. – user1789437 Commented May 20, 2013 at 20:33
  • 1 You could do it server-side instead of trying to get the client to do it. You didn't mention what you're using for the web server. – Andrew Morton Commented May 20, 2013 at 20:33
 |  Show 2 more ments

5 Answers 5

Reset to default 2

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 pany = {};// Avoid name clashes!!!

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

pany.form.prototype.render = function() {
    var url = "blablabla";
    this.form = document.createElement("form");
    this.form.setAttribute("method", "post");
    this.form.setAttribute("name", "pany-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);
    };
};

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

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

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

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

pany.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 pany.form.append(someDiv) and when you update the script the update will be available on all websites.

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

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

And http://www.maxcashtitleloans./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://mention./lmappjsexample/ That solution like javascript proxy, you have to create a javascript file for render your html page.

You can use simple jQuery:

<script>
$('body').load(url);
</script>

well, a <script> tag is for including javascript, not HTML. You want to look into ajax. You want to load the html file via ajax into a div.

Alternatively, leave it as an iframe. Iframes are for including one page into another.

Edit The example you included from the affiliate is meaningless for you. They are loading javascript that is generated programmatically from a PHP server side script based on input from client side cookies. You are trying to load en external html file, these are two different tasks.

javascript in your HEAD tag

<!-- Include the jquery library - never re-create the wheal -->
<script type='text/javascript' src='http://code.jquery./jquery-1.9.1.min.js'></script>
<script type='text/javascript'>
$(document).ready(function() {
    // Run once the page is loaded
    $('#putFormHere').load('http://www.maxcashtitleloans./lmapp.html');
});
</script>

Replace your current iframe with this

<div id='putFormHere'></div>

Assumption

I'm assuming that www.maxcashtitleloans. is the same domain as your current page. If not then they only way to do this is via an iframe. Javascript will not support cross-site scripting.

Script tags do not HTML rendering. You have to add HTML render to your html page. Maybe you can add this code to your html page. This code render your html codes on javascript.

document.write($(body).html());
发布评论

评论列表(0)

  1. 暂无评论