0

This code is not showing me alert:-

<script type="text/javascript">
var wloc = window.parent.location;
var abcd = wloc.substring(0,24);
alert(wloc);
alert(abcd);
</script>
Django Anonymous
  • 2,847
  • 16
  • 57
  • 103

3 Answers3

3

Make sure that your script has access to parent. Then modify script as given below

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

For location of current window try the script below

<script type="text/javascript">
window.onload = function(){
    var wloc = window.location.href;
    var abcd = wloc.substring(0,24);
    alert(wloc);
    alert(abcd);
}
</script>
Diode
  • 23,400
  • 8
  • 39
  • 50
1

add .href after 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>
mgraph
  • 15,016
  • 4
  • 38
  • 73
0

Below line is giving error. That's why it doesn't showing alert.

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

Use this instead

<script type="text/javascript">
  window.onload = function(){
    var wloc = window.parent.location.href;
    var abcd = wloc.substring(0,24);
    alert(wloc);
    alert(abcd);
 }
</script>
Kundan Singh Chouhan
  • 13,432
  • 4
  • 26
  • 31