当前位置:网站首页>About the iframe anchor, the anchor is offset up and down, and the anchor has page display problems Srcdoc problem of iframe
About the iframe anchor, the anchor is offset up and down, and the anchor has page display problems Srcdoc problem of iframe
2022-06-24 08:13:00 【Take drums and think about music】
Recent development projects , Need to develop iframe page , And get a navigation bar outside , After clicking iframe To jump to the corresponding anchor position .
Encountered some pits , I hope it can help you after sharing .
1. The back end is a direct one html file , So I didn't create it with iframe Of src To accept , It's about using srcdoc Show directly . You can search for iframe.src Is the corresponding url. and srcdoc Is the corresponding html file
2. Anchor point , We can't just give iframe Internal direct anchor , because iframe It can't be operated directly . Need to use iframe Of postMessage event . Specific you can baidu specific documents . Method
(1) Add a click event to the outside navigation page ( for instance hanldClick)
hanldClick() {
// val You clicked iframe The corresponding anchor point id
document.getElementById('iframeId').contentWindow.postMessage(val, '*')
}
(2) stay iframe Inside script in , Add listening Events
window.addEventListener('message', function (e) {
console.log(e.data)
}, false)
ad locum , Will meet pit :
A pit , The anchor point will drive the page to move up as a whole . Never use margin-top, After you use it, you find it useless . Use padding-top . Other small offsets are handled by ourselves , I don't want to elaborate here
Pit two , If you are in the iframe It reads like this , You will find iframe It has become your whole big html page , And navigation is useless
window.addEventListener('message', function (e) {
const link = document.createElement('a');
link.href = `#${
e.data}`;
document.getElementById('#${e.data}').appendChild(link);
link.click();
}, false)
The correct way to write it is :
The correct way to write it is :
window.addEventListener('message', function (e) {
// use window, Do not use document, It should be the scope problem , Caused by pollution
window.location.hash = `#${
e.data}`;
}, false)
If the article helps you , Just like it in the upper right corner of the article or at the end of the article !(づ ̄ 3 ̄)づ
If you like the articles shared by Pikachu , Just pay attention to bikachu !(๑′ᴗ‵๑)づ╭~
Given the limited personal experience , All viewpoints and technical research points , If there is any objection , Please reply directly to the discussion ( Do not make offensive remarks )
take , You're welcome !!! Send people roses , Fragrance in hand 
边栏推荐
- Online education fades
- Examples of corpus data processing cases (reading multiple text files, reading multiple files specified under a folder, decoding errors, reading multiple subfolder text, batch renaming of multiple fil
- Swift Extension NetworkUtil(網絡監聽)(源碼)
- Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
- 软件工程导论——第二章——可行性研究
- 3-list introduction
- 1-4metasploitable2介绍
- Selenium IDE的安装以及使用
- Model effect optimization, try a variety of cross validation methods (system operation)
- Graphmae ---- quick reading of papers
猜你喜欢

Vulnhub靶机:BOREDHACKERBLOG_ CLOUD AV

Application of JDBC in performance test

Installation and use of selenium IDE

1279_VMWare Player安装VMWare Tools时VSock安装失败解决

模型效果优化,试一下多种交叉验证的方法(系统实操)

Model effect optimization, try a variety of cross validation methods (system operation)

快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning

Mousse shares listed on Shenzhen Stock Exchange: gross profit margin continued to decline, and marketing failed in the first quarter of 2022

SCM stm32f103rb, BLDC DC motor controller design, schematic diagram, source code and circuit scheme

Future trends in automated testing
随机推荐
1279_VMWare Player安装VMWare Tools时VSock安装失败解决
Vulnhub target: boredhackerblog_ CLOUD AV
Auto usage example
Upgrade Mysql to the latest version (mysql8.0.25)
Live wire, neutral wire and ground wire. Do you know the function of these three wires?
UTC、GMT、CST
In the post epidemic era, the home service robot industry has just set sail
快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning
[C language] system date & time
Introduction to software engineering - Chapter 3 - Requirements Analysis
Leetcode 207: course schedule (topological sorting determines whether the loop is formed)
研究生英语期末考试复习
os.path.join()使用过程中遇到的坑
Simple refraction effect
Keep one decimal place and two decimal places
More appropriate development mode under epidemic situation
Shader common functions
The first exposure of Alibaba cloud's native security panorama behind the only highest level in the whole domain
Introduction of model compression tool based on distiller
Question 1: the container that holds the most water