此代码未向我显示警报:-
<script type="text/javascript">
var wloc = window.parent.location;
var abcd = wloc.substring(0,24);
alert(wloc);
alert(abcd);
</script>
最佳答案
确保您的脚本有权访问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>