Home>Article>Web Front-end> HTML prevents iframe from jumping to the page and uses iframe to embed the WeChat web version in the page.

HTML prevents iframe from jumping to the page and uses iframe to embed the WeChat web version in the page.

小云云
小云云 Original
2018-05-12 16:44:20 5462browse

What functions can be achieved by combining winform with html5? I suddenly had a whim and wanted to embed a WeChat web version in it. The editor below will introduce to you how to prevent iframe jumps in HTML and use iframes to embed the WeChat web version in the page. Let’s take a look. I hope it can help. Everyone.

I just want to make a small thing that combines winform with html5. I suddenly got interested and wanted to embed a WeChat web version in it.

Okay, as soon as the idea comes up, take action. The final effect is as follows:

From the beginning, I planned to embed an iframe in the page pointing to https ://wx.qq.com is OK, but I am still too naive, and the WeChat web version will automatically jump. The result is as shown below:

#So I searched online for a way to prevent iframe jump, which is to add two attributes of security="restricted"sandbox="" to the iframe tag. The former is a function of IE that prohibits js, and the latter is a function of HTML5.

Usesandbox="allow-scripts allow-same-origin allow-popups"to prevent jumps. However... the result is this:

Then I discovered that this jump is actually browsing to the jump page after closing the original page. So 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; } };

and then find that the result is still like this:

What is the reason? No response to the incident? Or is the jump in the WeChat web version too awesome? Just ignore this incident? So I created a new blank html and added the event separately for verification.

     

The result is feasible:

#But after embedding the iframe in the page, it jumps directly. You can try the following code.

     

When I had no idea, I kept turning it on and off to try to see if this method worked. Suddenly I discovered that if the page is closed within a short period of time after it is opened, the onbeforeunload event will not be triggered. After waiting for a few seconds and then closing the page, the event will be triggered and a prompt will appear.

Come on, try iframe delay assignment to src (JQuery is quoted here).

      

The result is indeed successful. A prompt will appear whether to leave this page. Click the Leave button. There is no jump on success. The picture below is a picture of 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 cancel button on the pop-up window, and it takes two times. The first time you open the page, the second time it will jump after scanning the code. Turn the page once. There is currently no way to solve this problem. I hope friends who have a solution to this problem can give me some suggestions.

Related recommendations:

Two ways to upload image files using native ajax and iframe frameworks

PHP uses iframe to upload and display images

Summary of methods of using JQuery to operate iframe parent pages and child pages

The above is the detailed content of HTML prevents iframe from jumping to the page and uses iframe to embed the WeChat web version in the page.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn