javascript - history.replaceState() 不起作用,在脚本中
问题描述
I am creating a addon.
The addon will be expanded in <iframe>
.
<div>
<iframe src="my/add-on/path">
<!-- my contents is expanded -->
</iframe>
</div>
The addon have <input>
parameters (date and time) a button that get and display datas.
Our customer requires
- Browser's reload button must act as click the button.
To solve this, there is some problems.
- On reload, parent don't open my add-on because my add-on is inside
<iframe>
(parent can change contents of<iframe>
). But parent can detect what add-on to open by a URL parameter.
To solve this problem, I tried to use history.replaceState() but don't worked like this fiddle. URL seems to be changed but not change URL inside browser bar. https://jsfiddle.net/3ema2yg7/
I want to know the way to solve this problem.
解决方案
我使用parent.history.replaceState()
as解决了这个问题
const url = new URL(parent.location.href)
url.searchParams.set('key', 'value')
parent.history.replaceState({}, '', url)
JSfiddle 不起作用,警告from accessing a cross-origin frame.
。但我的附加工作。
我很满意。
推荐阅读
- java - 在编码的 URL 上获取 MalformedURLException
- postgresql - prisma $queryRaw 不适用于字符串中的单引号
- facebook-graph-api - Facebook Resumable Upload API 中 file_offset 标头的用途是什么?
- html - 百分比 'min-height' 仅在元素具有带有 'display: flex' 的间接父级时才有效
- python - 如何读取 Python 中给出的输入数量
- mongodb - 如何使用golang在mongodb中批量插入
- python - 带有 tkinter 的 Windows
- flutter - 如何将参数传递给 onInit 方法
- sql - 在 SQL 中的特殊字符之后和之前将所有内容作为单独的列获取
- javascript - Google表格/应用程序脚本:在特定文件夹中创建新电子表格的功能