0

此代码未向我显示警报:-

<script type="text/javascript">
var wloc = window.parent.location;
var abcd = wloc.substring(0,24);
alert(wloc);
alert(abcd);
</script>
4

3 回答 3

3

确保您的脚本可以访问parent. 然后修改脚本如下

<script type="text/javascript">
window.onload = function(){
    var wloc = window.parent.location.href;
    var abcd = wloc.substring(0,24);
    alert(wloc);
    alert(abcd);
}
</script>

对于当前窗口的位置,请尝试以下脚本

<script type="text/javascript">
window.onload = function(){
    var wloc = window.location.href;
    var abcd = wloc.substring(0,24);
    alert(wloc);
    alert(abcd);
}
</script>
于 2012-08-15T17:52:36.487 回答
1

.href之后添加window.parent.location

<script type="text/javascript">
window.onload = function(){
    var wloc = window.parent.location.href;
    var abcd = wloc.substring(0,24);
    alert(wloc);
    alert(abcd);
}
</script>
于 2012-08-15T17:48:12.270 回答
0

下面的行给出错误。这就是为什么它没有显示警报。

var abcd = wloc.substring(0,24); 

改用这个

<script type="text/javascript">
  window.onload = function(){
    var wloc = window.parent.location.href;
    var abcd = wloc.substring(0,24);
    alert(wloc);
    alert(abcd);
 }
</script>
于 2012-08-15T17:51:59.160 回答