Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

JavaScript
<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>


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.
Posted
Updated 5-May-16 2:01am

1 solution

Define where on the page you want to inject the content

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


Then rather than response.write you use;

JavaScript
document.getElementById('myContent').innerHTML = xhr.responseText;
 
Share this answer
 
Comments
Nisarg Desai 5-May-16 7:28am    
well the problem is that selector can be anything because subscriber page is not under my control. so i want to render my text without specified a selector
F-ES Sitecore 5-May-16 7:39am    
The div to inject the code goes on your page with the javascript
Nisarg Desai 5-May-16 7:53am    
No not on my page its on subscribers page. i am serving response through web service. just like facebook flike, google plus index and pinit indexer.
Nisarg Desai 5-May-16 7:59am    
Okay I did solve this. Updating my Answer Here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900