I just want to make a small thing that combines winform with html5, and suddenly I have the interest to embed a WeChat web version in it. Well, once the idea comes out, let's take action. The final effect is as follows: At the beginning, I planned to embed an iframe in the page to point to https://wx.qq.com, but I was too naive and the WeChat web version would jump automatically. The results are as follows: So I searched online for a way to prevent iframe redirects, which is to add two attributes, security="restricted" and sandbox="" to the iframe tag. The former is IE's function of disabling js, and the latter is a function of HTML5. Use Then I found that this jump is actually closing the original page and then browsing to the jump page. Therefore, you can use the page closing event onbeforeunload to prevent the jump. So add the following code to the page: document.body.onbeforeunload = function (event) { var rel = "asdfawfewf"; if (!window.event) { event.returnValue = rel; } else { window.event.returnValue = rel; } }; Then I found that the result was still like this: What is the reason? No response to the incident? Or is it that the jump of WeChat web version is too awesome? Just ignore this incident? So I created a blank html and added this event alone for verification. <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> </head> <body></body> <script> document.body.onbeforeunload = function (event) { var rel = "asdfawfewf"; if (!window.event) { event.returnValue = rel; } else { window.event.returnValue = rel; } }; </script> </html> The result is feasible: However, after embedding the iframe in the page, it jumps directly. You can try the following code. <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> </head> <body> <iframe src="https://wx.qq.com/" frameborder="0" style="position: absolute;border: navajowhite;left: 0;height: calc(100% - 30px);width:100%"> </iframe> </body> <script> document.body.onbeforeunload = function (event) { var rel = "asdfawfewf"; if (!window.event) { event.returnValue = rel; } else { window.event.returnValue = rel; } }; </script> </html> When I was at a loss, I kept turning this method on and off to see if it worked. Suddenly I found that if the page is closed within a short time after it is opened, the onbeforeunload event will not be triggered. If you wait for a few seconds and then close the page, the event will be triggered and a prompt will appear. Come, try to delay the iframe to assign src value (JQuery is referenced here). <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> <script src="scripts/jquery-2.2.3.js"></script> </head> <body> <iframe id="iframe" frameborder="0" style="position: absolute;border: navajowhite;left: 0;height: calc(100% - 30px);width:100%"> </iframe> </body> <script> $(function () { setTimeout(function () { iframe.src = "https://wx.qq.com/"; },5000); }); document.body.onbeforeunload = function (event) { var rel = "asdfawfewf"; if (!window.event) { event.returnValue = rel; } else { window.event.returnValue = rel; } }; </script> </html> The result was successful. A prompt will appear asking whether to leave this page. Click the Stay button. No jump on success. The picture below is my finished product. It’s done. You can chat and transfer files normally, but you can’t take screenshots. The disadvantage is that to complete the login, you need to click the pop-up cancel button twice, the first time to open the page, and the second time after scanning the code, the page will jump again. There is currently no way to solve this problem. I hope that friends who know how to solve this problem can give me some suggestions. I will reply to you in a timely manner. Thank you very much for your support of the 123WORDPRESS.COM website! |
<<: Detailed explanation of MySQL persistent statistics
>>: Implementation of whack-a-mole game in JavaScript
Add secure_file_priv = ' '; then run cmd ...
Table of contents first step Step 2 Step 3 Step 4...
We hope to insert the weather forecast into the w...
<iframe src=”you page's url” width=”100″ he...
1. Inline reference: used directly on the label, ...
Refer to the tutorial on setting up FTP server in...
CSS3 can create animations, which can replace man...
Using fonts on the Web is both a fundamental skill...
Table of contents 1. Optional Chaining 2. Null va...
Table of contents 1. Analyzing MySQL from a macro...
I have been having this problem recently when desi...
Summary This article will introduce the following...
This article shares the specific code for JavaScr...
You might be wondering why you should use the pat...
Let me tell you about a recent case. A game log l...