作者casper67831 (casper)
看板Web_Design
标题[问题] 一段cross domain的动作看不懂
时间Sun Jun 30 22:13:17 2013
嗨~
我在学长的系统里看到一段code,
js
.....
{
var s = document.createElement('script');
s.src = "
http://192.168.100.100/index.php";
s.type = "text/javascript";
document.getElementsByTagName('head').appendChild(s);
}
function response_from_server()
{
alert("hi");
}
.....
然後在192.168.100.100这台server的 index.php 里写
<?php
echo "response_from_server()";
?>
我的browser domain 是192.168.1.1,当程式呼叫上面那段script後,
会去新创一个<script>的tag,然後去汇入另外一个domain的index.php资料,
而另外一个domain的index.php会直接呼叫browser这端的function并印出"hi"出来。
我的问题是:
因为 script injection算是安全性问题,
这样的写法有没有浏览器相容的问题??
其次,为什麽在index.php里写个echo function然後在网页端这边就可以执行??
再来,假设192.168.100.100这台server不稳或挂掉,
那网页这边会嚐试送几次GET request来要index.php这个资料??
如果server挂掉,那网页这边还会一直尝试跟192.168.100.100要资料吗??
有懂的人可以回覆吗?? 谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.195.205.130
1F:→ Darkland:1. 没有 2. 他只是个载入外部 js 的动作,只是来源是 php 06/30 22:33
2F:→ Darkland:产生的而已 3. 一次 06/30 22:33
3F:→ casper67831:第一次看到这种写法觉得很妙 06/30 23:03
4F:推 lyforever:coolshell.cn/articles/9749.html 06/30 23:12
5F:→ lyforever:可以参考上面这篇 js的装载与执行 06/30 23:12
6F:→ lyforever:你的code没有给的很清楚, 所以不知道100挂掉後 06/30 23:13
7F:→ lyforever:会送几次 XDD 06/30 23:14
8F:→ casper67831:你给得这个参考资料很好~ 谢谢 06/30 23:56
9F:→ Rplus:很多 bookmarket js 的作法都是这样的唷~ 07/01 01:32