如何在没有iframe的情况下将HTML文本呈现在第三方网页的div中? [英] How to render HTML text to be placed inside third party webpage`s div without iframe?

查看:76
本文介绍了如何在没有iframe的情况下将HTML文本呈现在第三方网页的div中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于我的Subsciber在网页上的任何位置生成html以及SVG代码(或者你可以说任何div)。



我想给一些javascript代码放在那个页面的div的一边,所以在那个div整个我的代码所在。



我不喜欢我想使用iframe,因为高度和宽度没有定义为自动化。



这里我试过了,我还在尝试。



我尝试了什么:



I want to generate html as well as SVG code based on my Subsciber`s any of the position of on web page (or you can say any of the div).

I want to give some javascript code to be put in side of that page`s div so at that div whole my code place.

I don`t want to use iframe because height and width is not defined its automated.

here what i have tried and i am still trying.

What I have tried:

<html>
    <head>
    <title>TODO supply a title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
    <div>TODO write content</div>        
    <div>
    <script>
        (function(){
            var xhr=new XMLHttpRequest();xhr.open("get","request Url of my side",true);xhr.send();
            xhr.onreadystatechange=function(){ if(xhr.readyState==4 && xhr.status==200){document.write(xhr.responseText);}}
             }());

    </script>
    </div>   
</body>
    </html>





但是这里发生的事情是在响应整个页面被加载之前和document.write()擦除现有内容并放置我的responseText。



任何帮助将不胜感激。



But what happening here is before response came whole page was loaded and document.write() erase existing content and place my responseText .

Any Help will be appreciated.

推荐答案

定义页面上的位置想要注入内容



Define where on the page you want to inject the content

<div id="myContent"></div>





然后您使用而不是response.write;





Then rather than response.write you use;

document.getElementById('myContent').innerHTML = xhr.responseText;


这篇关于如何在没有iframe的情况下将HTML文本呈现在第三方网页的div中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆