Hello everyone, help to insert html markup in JS.

I wrote the code on one domain online assistant.

HTML

<!--<div id="open_chat_dev2Studio"><div class="shc sh_btn_char_trans">О</div><div class="shc sh_btn_char_trans">н</div><div class="shc sh_btn_char_trans">л</div><div class="shc sh_btn_char_trans">а</div><div class="shc sh_btn_char_trans">й</div><div class="shc sh_btn_char_trans">н</div><div class="shc sh_btn_char_trans"><br/> </div><div class="shc sh_btn_char_trans">п</div><div class="shc sh_btn_char_trans">о</div><div class="shc sh_btn_char_trans">м</div><div class="shc sh_btn_char_trans">о</div><div class="shc sh_btn_char_trans">щ</div><div class="shc sh_btn_char_trans">ь</div></div><div id="chats_room_dev2Studio" style="display:none;"><div id="panel_work_groups"><div class="text9834">ОНЛАЙН ПОМОЩНИК </div> <div class="dfh_wel"></div></div><div id="loading"></div><form method="POST" id="logins" action='javascript:void(null);' onsubmit='call()'><input type="hidden" name="id" value="24324"><textarea name="mess" id="mess" placeholder="Опишите Ваш проект или задайте нам вопрос."></textarea><input type="submit" value="Отправить"></form><div style="clear:both;"></div></div> 

And js

 $('#open_chat_dev2Studio').click(function(){ $('#chats_room_dev2Studio').slideToggle(); $('#open_chat_dev2Studio').slideToggle(); return false; }); $('.dfh_wel').click(function(){ $('#chats_room_dev2Studio').slideToggle(); $('#open_chat_dev2Studio').slideToggle(); return false; }); function call(){ var msg=$('#logins').serialize(); $.ajax({ type:'POST', url:'//url/server/send.php', data:msg, success:function(data){ $("#mess").val(""); gsd() $('#loading').append(data); },error:function(xhr,str){ } }) } function update() { var last_id=$(".im_ch:last").attr("id"); $.ajax({ type:'POST', url:'//url.com/server/uploade.php', data:{'last_id':last_id}, success:function(data){ $('#loading').append(data); gsd() },error:function(xhr,str){ }})} setInterval("update()", 1000); function gsd(){ $("#loading").scrollTop(10000000000); } 

So, the code is completely working, only a problem: I need to connect this code from one domain to another, such as a frame, but the frame does not roll. (

You can somehow write this code in pure JS and connect with this type:

 <script src="min.js"></script> 

Or somehow load it as a frame, only with JS technology?

Rookie everything, found nothing. (
What can be done, how to connect the code to another domain?

I tried to load it like this:

 $("#div1").load("demo_test.txt #p1"); 

It does not work like that.

  • If you have an <iframe> and you want to change its content using the parent page's JS, then this is impossible! - ferrari

1 answer 1

Download a script from a server on another domain js that contains your html code (screened, of course) and js code inside a function that needs to be called after loading the script. another.domain.rf / script.js contains the following code:

 funcation runMe(){ var htmlCode ="тут ваш экранированный html"; $('#место-куда-вставлять-html').html(htmlCode); //тут вставляете ваш js код $('#open_chat_dev2Studio').click(function(){ $('#chats_room_dev2Studio').slideToggle(); $('#open_chat_dev2Studio').slideToggle(); return false; }); //итд } 

</ code>

and upload it to the page via

 <script src="другой-домен.рф/script.js"></script> <script type="text/javascript"> jQuery( document ).ready(function( $ ) { runMe(); }); </script> 

Here they do this through jsonp.