在專案開發中我們常常會遇到彈窗,有的是透過div模擬彈窗效果,有的是透過iframe,也有透過window自帶的open函數開啟一個新的視窗。今天要跟大家分享的是最後一個透過window.open()函數開啟頁面進行資料互動。首先看下效果圖:
Document
<script><br />
var test = document.getElementById('test');<br />
test.onclick = function() {<br />
window.open('./window.html?param1=name¶m2=password', '_blank','width=960,height=650,menubar=no,toolbar=no,location=no,directories=no,status=no ,scrollbars=yes,resizable=yes');<br />
};<br />
window.getContent = function(tx) {<br />
document.getElementById('content').innerText = tx;<br />
}<br />
</script>
Document
<script><br />
var params = location.href.substring(location.href.lastIndexOf('?') 1).split('&');<br />
document.getElementById('content').innerText = params;<br />
var city = document.getElementById('city');<br />
city.onchange = function() {<br />
window.opener.getContent(city.value);<br />
}<br />
</script>