Javascript无法删除DIV

时间:2017-08-13 18:25:49

标签: javascript html css iframe

实际上,我向我网站上的其他用户提供了iframe,但是如果在某些用户使用了iframe代码,我希望从中删除特定的 DIV 其他网站,我只允许我的网站在iframe内显示特定的Div。

我已经编写了一个在 localhost / xampp 服务器上完美运行的代码,但是这段代码在现场网站上不起作用我不知道我做错了什么?

这是我的实际代码

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

1 个答案:

答案 0 :(得分:0)

您的代码无效,因为变量{'_id':'BE3523','time':'18:20','number':'BE3523','destination':'Bordeaux','status':'Scheduled'} 获取您自己的域名并与变量frameLocation匹配。要解决此问题,您必须使用whiteLocation函数可能在某个其他变量中,然后从中提取域名并在document.referrer中重复使用。

您可以尝试使用 jsFiddle

或以下是解决问题的代码

frameLocation