开发者

How javascript gets someother website data?

Well i am a bit confused..

I saw a service known as Zopim.. What they do is they provide you with a small piece of code:

such as

<!-- Start of Zopim Live Chat Script --> 
 <script type="text/jav开发者_StackOverflow社区ascript"> 
    document.write(unescape("%3Cscript src=\'" + document.location.protocol +
    "//zopim.com/?zopim\' type=\'text/javascript\'%3E%3C/script%3E"));
 </script>  
<!-- End of Zopim Live Chat Script --> 

you just need to place it in the footer and ur done..

Can any body let me know how this works and from where i can learn this..

+

how can they even set the CSS with this and also the looks?

Awaiting for your replies...

Thanks


That code is creating a reference to a Javascript script hosted on their server. That reference on your page allows that script to access all the elements on your page (including their styles) through the DOM (Document Object Model) and to change them. All of this takes place in the user's browser.

Edit: Here's an example. Say I have a script on my site at http://www.mysite.com/myscript.js that does this:

document.body.style.backgroundColor = "#00FFFF"

Then you put this on your page:

<script type="text/Javascript">
    document.write("<script src='" + document.location.protocol + "://www.mysite.com/myscript.js'></script>");
</script>

Then when a user loads your page, and the user's browser gets to that code, it will write out a script tag that references my script. It will then process that script tag, which basically downloads my script (to the user's browser) and runs it on your page (which is already on the user's browser). My script, in turn, changes the background color of the document (your page, running on the user's browser), because it acts like it was part of your page all along.

By the way, the reason you're using document.write instead of just linking directly to my script is so that if your page uses SSL, so will the link, so the user won't get any annoying messages that my script isn't secure.


This code creates a <script> tag that loads a script from http(s)://zopim.com/?zopim.

The generated <script> tag is a regular Javascript script that can do whatever it wants to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜