Like the title, it may not be clear enough.
There is a demand at hand. The product manager said: "Xiao Hu, our product needs to add a new function, which is to be able to display well-written H5 pages, or provide web page display to users, such as displaying such-and-such news. Website"
I think, since I want to do such a rogue thing, I have used iframe to embed third-party pages in the past, so I might as well use this, and I haven't found any other methods.
Then the problem arises. For example, if a news website embeds it, it becomes the main focus of the website and directly kills my html page! After unremitting efforts, it was discovered that the webpage had an "anti-operator hijacking code"; the code is as follows:
<!-- 反运营商劫持 S -->
<style type="text/css">
html {
display:none;
}
</style>
<script>
if( self == top ) {
document.documentElement.style.display = 'block' ;
} else {
top.location = self.location ;
}
</script>
<!-- 反运营商劫持 E -->
Can anyone help me crack it?
The following methods have been used:
//在主窗口的</head>标签前面添加
<script type="text/javascript">
var location=document.location
</script>
//或者:
<script type="text/javascript">
var location=""
</script>
However, there are no eggs. . .
What the respondent on the first floor said is absolutely true;
The current solution is to disable jumps through the "sandbox attribute" sandbox of ifram;
All mainstream browsers support the sandbox attribute. However, IE 9 and earlier versions do not support the sandbox attribute , and Opera 12 and earlier versions also do not support this attribute .
If you want to be compatible with IE8 and below, please ignore the answer! ! !
iframe’s sandbox attributes and values:
If you don’t set allow-top-navigation, you won’t be forced to jump! ! !
Of course, you will find that the page content is not displayed but does not jump. Taking xw.qq.com as an example, you will find that it is because the html in the iframe is set to "display:none";
The antidote has not been found on the PC yet
The error is reported across domains! !
Normal interface (front-end page in android webview):
Code (self-debugging, pc bypass! ):
var iframe = document.createElement("iframe");