1

Actually I am offering an iframe to other users from my website that works perfectly but I want to remove a specific DIV from it if iframe code is used on some other website, I only allowed my site to show specific Div inside iframe.

I have already wrote a code that works perfectly on localhost/xampp server but this code won't work on live site I don't know what I am doing wrong in it?

Here is my actual code

<script type="text/javascript"> 
var frameLocation = window.location.hostname; 
var whiteLocation = "<?php echo $ShowMyDomain; // prints mywebsite.com ?>"; 
if (whiteLocation != frameLocation) { 
$('#adprimary').remove(); 
} 
</script>
Rtra
  • 514
  • 12
  • 25

1 Answers1

0

Your code won't work because the variable frameLocation gets your own domain name and match with variable whiteLocation. To resolve this issue you must use document.referrer function may be in some other variable then extract the domain name from it to and reuse it in frameLocation.

You can try this working jsFiddle

or here is the code that will resolve your problem

<script type="text/javascript"> 
$(document).ready(function(){ 
var urlGet = document.referrer; 
var frameLocation = urlGet.match(/:\/\/(.[^/]+)/)[1]; 
var whiteLocation = "<?php echo $ShowMyDomain; // prints mywebsite.com ?>"; 
if (whiteLocation!=frameLocation) { 
$('#adprimary').remove(); 
}
}); 
</script>
Rtra
  • 514
  • 12
  • 25