javascript - 如何从嵌入式页面访问父变量?
问题描述
我想创建一个出现在网页上的便笺,当我键入内容时,内容与 URL 一起存储在数据库中作为参考
例如,我去一个 BBC 页面,我点击 cmd+escap 并出现我的便笺(这是一个Tampermonkey脚本)
function addEmbed(){
localStorage.setItem("myUniqueAPIcode", window.location);
var iframe = document.createElement("iframe");
iframe.type="text/html"
iframe.src="http://localhost:8080/webhighlights"
iframe.style.cssText = `position: absolute;
top: 0;
right: 0;
z-index: 999999;
height: 100vh;`
return iframe
}
该代码有效,因为便笺出现了。这是一个 Vue 页面。但我无法访问本地存储值
mounted() {
if (typeof Storage !== "undefined") {
if (localStorage.myUniqueAPIcode) {
this.api = localStorage.myUniqueAPIcode
}
}
},
};
我有点知道为什么,tampermonkey 脚本在 BBC 页面上设置值,而 Vue 代码在 localhost 页面中查找。
但是,在此之前,我尝试将粘性表单附加到页面本身,但某些网站不允许执行获取请求。
有没有办法做到这一点?
解决方案
推荐阅读
- c# - 是否可以在一行中检测捕获组的组合和排列?
- android - Android studio创建项目时如何修改gradle版本
- kubernetes - Kubernetes 持久卷不允许读取或写入
- node.js - 用节点和猫鼬实现接口的正确方法是什么?
- python - 如何使用python将多个excel表合并到一个excel表中?
- swiftui - 导航栏中的 SwiftUI 文本字段一次只允许一个字符
- python - 如何使用 python 的库 Urwid 在 TUI 应用程序中运行 youtubedl 而不会阻塞整个应用程序?
- c++ - 如何从严格的技术意义上解释 C++ 左关联逻辑?
- javascript - 如何改进领域查询使其不会阻塞 UI
- machine-learning - 在使用 train_test_split 拆分数据之前使用 sklearm.preprocessing.PowerTransformer() 的问题