protld protld - 3 months ago 10
HTML Question

Redirect to page if iFrame url is google.com

I want to use javascript, so if an iframe on my page's url became 'https://google.com.eg' it must do a function

Function for example:


  • Redirect to error.php using "window.href"

  • Show javascript box saying "error"



My iframe is:

<iframe src="https://translate.google.com.eg" id="myframe"></iframe>


And I want to prevent my site visitors to go to the Google homepage.

Thanks!

Answer

If you are using jquery $(document).ready(function (){ var a = $('#myiframe').attr('src'); If(a == 'www.google.com' || a=='google.com' || a=='https://google.com.eg’){ window.location.href="error.php"; } });

Comments