Edited question
In summary:
I got 2 sites
siteA.com
siteB.com
Iframe belong to siteB.com
But i want allow siteA.com to iframe siteB.com page too. However anything that not siteA or siteB.com will be redirect to siteA.com
using javascript, how do i check, consider to ignore with www or without www(wildcard) and also that my site could be siteA.com/pretty-url
How do i do the check and add in the security with javascript , which any random site not authorize will result in window.top.location.href being redirect to siteA.com
Thanks for all help, new here 🙂
Something like this?:
The first check is making sure you only run this code if your site is in a frame.
The second check is looking to see if url of the top frame (browser window) contains your domain. We need to ignore the querystring/anchor incase it looks something like this: http://notmine.com/path/file.html?subframe=mysitedomain.com
This would still match:
In the .match(…), you could include http:// or https://.
Update to answer your edits: