2013-05-20 1 views
4

내가 해제 방법 용서해주십시오 다음이 코드를 사용하는 방법에 대한 생각하면,하지만 어떻게 든 다른 서버에서 많은 웹 사이트 내부에 HTML 양식을 표시자바 스크립트 document.write를 통해 HTML 양식을 표시 하시겠습니까?

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

같은 것을 사용하는 것이 가능하다?

나는 회사 변경의 필요에 따라 지속적으로 업데이트 될 단일 HTML 양식을 보유하고 있으며, IFRAME 호출에서 해당 양식을 가져오고 싶습니다.

같은 목표를 향해 다른 질문은 내가

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

PHP를 사용하는 것이 더 좋을 수 있습니다. –

+0

모든 서버를 제어합니까? – bfavaretto

+0

@ Mr.Polywhirl과 PHP가 어떻게 처리해야할까요? – J0HN

답변

1

그래, 해결책이 있습니다. 이런 embed 코드는; 이 같은

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

그리고 http://www.maxcashtitleloans.com/lmapp.js는 :

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(); 

그게 잘 작동합니다. 그리고 당신을위한 데모 : http://commention.com/lmappjsexample/ 그 해결책은 자바 스크립트 프록시와 같은, 당신은 HTML 페이지를 렌더링하기위한 자바 스크립트 파일을 만들어야합니다.

0

사용할 수를 사용하는 제휴 마케팅 회사를 알고

을 "어떻게 IFRAME을 사용하여 웹 사이트에 사이트 콘텐츠를 표시 할 수 없습니다" 간단한 jQuery :

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

스크립트 태그는 HTML 렌더링이 아닙니다. html 페이지에 HTML 렌더링을 추가해야합니다. 어쩌면이 코드를 html 페이지에 추가 할 수 있습니다. 이 코드는 자바 스크립트에 HTML 코드를 렌더링합니다.

document.write($(body).html()); 
+0

오? 이걸 부를 방법에 대한 도움? – user1789437

+1

코드는 어떤 값도 수행하지 않습니다. 코드가 너무 복잡하여 – Justin808

+0

문서 쓰기 본문이 작동하지 않습니다. 교차 도메인 xml과 함께 아약스로드를 사용할 수있는 다른 방법. –

0

글쎄, <script> 태그는 HTML이 아닌 javascript를 포함합니다. 너는 ajax을보고 싶다. div에 ajax를 통해 html 파일을로드하려고합니다.

또는 iframe으로 두십시오. iframe은 한 페이지를 다른 페이지에 포함시키기위한 것입니다.

편집 귀하가 계열사에서 포함시킨 예는 귀하에게 의미가 없습니다. 클라이언트 측 쿠키의 입력을 기반으로 PHP 서버 측 스크립트에서 프로그래밍 방식으로 생성 된 자바 스크립트를로드하고 있습니다. 당신은 외부 HTML 파일을로드하려고하는데, 이것은 두 가지 다른 작업입니다. 당신의 HEAD 태그

<!-- Include the jquery library - never re-create the wheal --> 
<script type='text/javascript' src='http://code.jquery.com/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.com/lmapp.html'); 
}); 
</script> 

에서

자바 스크립트 내가 www.maxcashtitleloans.com가 같은 도메인입니다 있으리라 믿고있어

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

가정으로 현재 iframe을 교체 너의 큐렌처럼 t 페이지. 그렇지 않다면 그들은 방법은 iframe을 통해입니다. Javascript는 크로스 사이트 스크립팅을 지원하지 않습니다.

+0

이렇게하면보기 소스에서 HTML 양식의 코딩을 볼 수 있습니까? 아니면 내 첫 번째 질문에있는 방법처럼 그것을 숨길 것인가? – user1789437

+0

IFRAME 메소드가 아닌 Ajax 메소드. – user1789437

+0

브라우저에 따라, 일부는 javascript가 DOM 요소를 생성하는지 검사 할 수도 있고, 일부는 그렇지 않을 수도 있습니다. 사용자가 포함 된 HTML을 숨기려고하면 * 할 * 방법이 없습니다. – Justin808

2

나는 약간 다른 접근 방식을 제안 할 것이다.

JavaScript를 사용하여 HTML 양식을 만들고 동일한 소스를 사용하여 다른 모든 웹 사이트에 해당 스크립트를 포함하십시오.

form.js은 모든 웹 사이트에 포함하려는 파일이라고 가정합니다.

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

이제 단순히 다른 웹 사이트에 forms.js 포함하지만 스크립트를 유지할 수 있도록, 해당 웹 사이트의 모든 같은 src를 사용하십시오 최신 정보.

이제 해당 웹 사이트마다 company.form.append(someDiv)과 함께 양식을 추가 할 수 있으며 스크립트를 업데이트하면 모든 웹 사이트에서 업데이트를 사용할 수 있습니다.

+0

이 양식은 자바 스크립트 양식이 아닌 HTML 양식입니다. 여전히 작동할까요? – user1789437

+0

이것은 OP에서 작동하지 않습니다. OP는 양식이있는 HTML 페이지를 포함하려고합니다. – Justin808

+0

나는 OP가 JS 또는 HTML을 잘 모르는 경우 (스크립트 태그를 통해 HTML을로드하려고 할 때 가정하는) 그럼 그가 갈 수있는 최선의 방법이 아닐 수도 있습니다. – Justin808