Getting Value From Popup Window Using only JS amp; HTML(仅使用 JS amp; 从弹出窗口中获取价值HTML)
问题描述
是否可以从弹出窗口中获取值?此外,我只想使用 JS 和 HTML,即没有 PHP.这甚至可能吗?我在这里看到过类似这样的其他帖子:
Is it possible to get a value from a popup window? Additionally I would like to use JS and HTML only, i.e. no PHP. Is this even possible? I've seen other posts on here like this one:
从弹出窗口中获取价值
但那是在 aspx 中的.
but that's in aspx.
我google了一下,找到了这个链接:
I have googled a bit and found this link:
http://www.bignosebird.com/js/popmap.shtml
但是,它可以在那个家伙的网站上工作,但当我复制和粘贴它时,我可能是个菜鸟,所以这就是我所拥有的:
However, it works on that guys site but not when i copy and paste it, I may be a noob so this is what I have:
parent.html
<html>
<head>
</head>
<body>
<form>
<INPUT TYPE="TEXT" NAME="maparea" SIZE=2 VALUE="">
<input type=button onClick='targetitem = document.forms[0].maparea; dataitem = window.open("map.shtml", "dataitem", "toolbar=no,menubar=no,scrollbars=yes"); dataitem.targetitem = targetitem' value="Show Map">
</form>
</body>
</html>
map.shtml
<html>
<head>
<script>
function select_item(item)
{
targetitem.value=item;
top.close();
return false;
}
</script>
</head>
<body>
<CENTER>
<B>Our Map</B>
<BR>
<IMAGE SRC="map1.gif" ISMAP USEMAP="#MAP1">
<MAP NAME="MAP1">
<AREA SHAPE=RECT COORDS="11,10,116,133" HREF="" onClick='return select_item("1")'>
<AREA SHAPE=RECT COORDS="121,11,227,172" HREF="" onClick='return select_item("2")'>
<AREA SHAPE=RECT COORDS="11,140,115,226" HREF="" onClick='return select_item("3")'>
<AREA SHAPE=RECT COORDS="119,177,225,227" HREF="" onClick='return select_item("4")'>
<AREA SHAPE=default HREF="" >
</MAP>
</CENTER>
</body>
</html>
任何帮助将不胜感激.
推荐答案
它适用于我(使用 Firefox 20.0).但是代码确实又丑又旧,也许你应该研究一下 MSDN Window 了解它在 firefox 中的工作方式(Window 对象可能会改变其在其他浏览器中的行为).啊,当然还有 ECMAScript .但要介绍多种解决方案之一,您可以尝试以下方法:
parent.html
It works for me (using Firefox 20.0). But the code is really ugly and old though, probably you should study the present standards of MSDN Window to understand how it works in firefox (Window object may change its behaviour in other browsers). Ah, and of course the ECMAScript . But to introuduce one of the multiple solutions, you could try this:
parent.html
<input type="text" id="output"/>
<button id="show">Open</button>
<script>
document.getElementById('show').addEventListener('click', function(){
window['output'] = document.getElementById('output');
window.open('map.html')
});
</script>
maps.html(我更改了扩展名!)
<input type="text" id="user_text"/>
<input id="send" type='button' value'send'/>
<script>
document.getElementById('send').addEventListener('click', function(){
window.opener['output'].value = document.getElementById('user_text').value;
})
</script>
这篇关于仅使用 JS & 从弹出窗口中获取价值HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:仅使用 JS & 从弹出窗口中获取价值HTML


基础教程推荐
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01