此代码未向我显示警报:-
<script type="text/javascript">
var wloc = window.parent.location;
var abcd = wloc.substring(0,24);
alert(wloc);
alert(abcd);
</script>
此代码未向我显示警报:-
<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>
.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>
下面的行给出错误。这就是为什么它没有显示警报。
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>