gpt4 book ai didi

javascript - 如何将弹出窗口更改为基本页面

转载 作者:行者123 更新时间:2023-12-03 00:22:31 25 4
gpt4 key购买 nike

我在弹出窗口上有一段 Javascript 代码。现在我需要在不弹出的情况下使用它。意思是在一个由 iframe 组成的页面中。

在 Iframe 内,有一个页面,其表单名称为“ChatMsg”,文本字段名称为“mesg”。

所以我需要将 onclick 脚本放在主页上,它应该将值传递到 iframe 页面。

我为iframe添加了ID,iframe id是btnLocFrame

当前首页的代码是下面给出的前两个代码部分,form是代码的第三部分(iframe的源页面)。

我尝试通过将 window.opener 更改为 window.top 来更正代码,但它不起作用

<a href="javascript:pick(':IG');" alt=":IG" title=":IG"><img class="img-responsive" src="https://www.onlanka.com/chat/converts/smile7.gif"></a>   


<script language="javascript">
function pick(symbol) {
if(window.opener) window.opener.document.chatMsg.mesg.value += (window.opener.document.chatMsg.mesg.value == "") ? symbol : " " + symbol;
}
</script>
<form name="chatMsg">
<input type="text" name="mesg" id="mesg" maxlength="512" value="" autocomplete="Off">
</form>

我原本希望在单击链接后将链接的指定值传递到表单文本字段,但它不起作用。

请帮我改正代码

最佳答案

当您尝试使用模式将表情符号代码放入 Iframe 元素时,请尝试更改您的 pick 函数,如下所示

function pick(symbol) {

var iframe = document.getElementById('btnLocFrame');
var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;

var oldValue = innerDoc.getElementById("mesg").value;

innerDoc.getElementById("mesg").value = oldValue + symbol;

//if (window.opener) window.opener.document.chatMsg.mesg.value += (window.opener.document.chatMsg.mesg.value == "") ? symbol : " " + symbol;
}

关于javascript - 如何将弹出窗口更改为基本页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54249954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com