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,987
  • 16
  • 58
  • 106

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
  • 24,570
  • 8
  • 40
  • 51
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,238
  • 4
  • 41
  • 75
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,952
  • 4
  • 27
  • 32