简体   繁体   中英

Get data from external site and then modify it

If somesite(external site) returns a string like "cost is 10$", would it be possible to display it as "price:10$" using only javascript and on my own site? External site is facebook.com or something. My site is my site.


Hey guys. I am editing a question. I want to get data FROM external site. I donnt need just modify string it's easy, of course. I need something like.

var str = GetData("http://facebook.com/blablbal");

str.Replace('blbablab','blabal');

ShowToUser(str);

I hope you understand me. Sorry i'm not a native speaker.


I mean get data using XMLHttpRequest or iframe and then modify it. One of the moderators edited my question and replace title. But he donnt understand what i actually mean.


Here is real example.

http://vkontakte.ru/share.php?act=count&index=[index]&url=http://talismansochi2014.ru/grandfather_frost/go.php returns

VK.Share.count(0, 8718);

i want to get 8718 and show user just number 8718. And i can use only JS. I cannt make request from server and then return webpage.


Maybe i need recreate question or provide some additional information?

You could do:

"cost is 10$".replace(/cost is /, "price:");

That should return "price: 10$".

如果格式始终相同,则可以执行以下操作:

var string = "price:"+returnString.substring(8);

Try this

<script type="text/javascript">

var str="cost is 10$";
document.write(str.replace("cost is","price:"));

</script>

尝试以下alert('price:'+('cost is 10$').match(/\\d+/)+'$') ,用持有此字符串的var替换cost为10 $

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM