当前位置:网站首页>I found another cross domain method by chance. I don't know if anyone has ever played this way
I found another cross domain method by chance. I don't know if anyone has ever played this way
2022-06-29 20:18:00 【Full stack programmer webmaster】
as everyone knows ,jsonp Take advantage of the feature that the browser does not restrict the loading of cross domain external resources , Use script label src Property request interface , Load data , stay script Trigger the function declared in advance to get the data , The front-end predecessors are sharp in their operation .In fact, one-way interface calls can be implemented using any resource tag , The key is how to get the data returned from the back end to realize two-way interaction . Modern browsers offer getComputedStyle This API, Made by js You can get the final application of an element css style .( Low version IE In Chinese, it means currentStyle). As shown below :
In this way , We can do that css Style to get the desired data text 1. Using pseudo class ::after or ::before Of { content:”{ data }” } Or make use of font-family:”{ data }”
data.css Code
.data-div{
font-family: "{a:'1'}";
}2. Dynamic loading css style , And monitor it load event , I use static files here ( The above data.css), If you are interested, you can write an interface to try .
<div class="data-div" style="width:50px;height:50px;background:red;"></div>
<script>
div = document.getElementsByClassName("data-div")[0] // Apply style to data labels
div.onclick = function(){
var link = document.createElement("link");
link.rel = "stylesheet"
link.href = "/data.css"
link.type = "text/css"
link.onload = function(){
console.log(window.getComputedStyle(div)["fontFamily"]); // Get written in font-family Attribute data
}
document.head.appendChild(link)
}
</script> 3. Click on the data tab , You can see the output as follows :
PS: This method and JSONP It also needs the cooperation of the back end to splice the data to the front end according to certain rules , In fact, there is no egg to use now , It is rarely used nowadays JSONP Implement cross domain requests . But it's OK to play by yourself , By the way, pay tribute to the wave JSONP, Pay tribute to a wave of predecessors
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/101349.html Link to the original text :https://javaforall.cn
边栏推荐
- 从众伤害的是自己
- Nutch2.1在Windows平台上使用Eclipse debug 存储在MySQL的搭建过程
- Sword finger offer 66 Building a product array
- Codeforces Global Round 21 C D E
- 使用Gunicorn部署web.py应用
- 2021 CCPC Harbin J. local minimum (thinking question)
- data link layer
- [network orientation training] - Enterprise Park Network Design - [had done]
- [buuctf.reverse] 142_ [SUCTF2019]babyunic
- 2021 CCPC Harbin E. power and modulo (thinking questions)
猜你喜欢

Cmake开发-多目录工程

Win7 easy connect 提示:选路连接失败,可能当前连接网络异常,请稍后重试

关于印发宝安区重点产业项目和总部项目遴选及用地保障实施细则(2022修订版)的通知

Flutter calls Baidu map app to realize location search and route planning

Flume configuration 4 - Custom source+sink

CorelDRAW最新24.1.0.360版本更新介绍讲解

Real time tracking of bug handling progress of the project through metersphere and dataease

Tag based augmented reality using OpenCV

Finally, Amazon~

数据链路层
随机推荐
Codeforces Global Round 21 C D E
Regular expression series of mobile phone numbers
Flume-ng配置
Flume配置3——拦截器过滤
【编译原理】语义分析
Oracle保留字查询
关于印发宝安区重点产业项目和总部项目遴选及用地保障实施细则(2022修订版)的通知
Chapter II (physical layer)
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
Detailed description of gaussdb (DWS) complex and diverse resource load management methods
[boutique] detailed explanation of Pinia
Linux安装MySQL8
ASP. Net core creates razor page and uploads multiple files (buffer mode) (Continued)
[USB flash disk test] in order to transfer the data at the bottom of the pressure box, I bought a 2T USB flash disk, and the test result is only 47g~
go: 如何编写一个正确的udp服务端
Bigder:自动化测试工程师
Win7 easy connect 提示:选路连接失败,可能当前连接网络异常,请稍后重试
社区访谈丨一个IT新人眼中的JumpServer开源堡垒机
【编译原理】语法分析
mapbox-gl开发教程(十二):加载面图层数据