我试图在href链接上的每次点击时打开新窗口。 但窗口仅替换为新页面的值,每次单击都会打开一个空白窗口。我在很多例子中都尝试了样品,但没有用。
以下是示例代码段..
var mapForm = document.createElement("form");
mapForm.target = "Map";
mapForm.method = "POST"; // or "post" if appropriate
mapForm.action = "../TestWindowsSample.jsp";
var mapInput = document.createElement("input");
mapInput.type = "hidden";
mapInput.name = "selectedId";
mapInput.value = selectedId;
mapForm.appendChild(mapInput);
document.body.appendChild(mapForm);
map = window.open("", "Map"+(windowCount++), "status=0,title=0,height=600,width=800,scrollbars=1");
if (map) {
mapForm.submit();
} else {
alert('You must allow popups for this map to work.');
}
答案 0 :(得分:0)
您现在只有一个目标"Map"
另外我假设selectedId
和windowCount
设置在其他地方,对吗?
尝试
var windowCount = 0;
var selectedId = "some string";
var mapForm;
.
.
.
mapForm = document.createElement("form");
var tgt = "Map" + (windowCount++); // define the target here
mapForm.target = tgt;
mapForm.method = "POST"; // or "post" if appropriate
mapForm.action = "http://www.zensolutions.co.nz/dev/httpdump";
var mapInput = document.createElement("input");
mapInput.type = "hidden";
mapInput.name = "selectedId";
mapInput.value = selectedId + tgt; // is this set somewhere?
mapForm.appendChild(mapInput);
document.body.appendChild(mapForm);
map = window.open("", tgt,"height=600,width=800,scrollbars"); // reuse target here
if (map) {
setTimeout(function() { // give IE time to respond
mapForm.submit();
}, 10);
} else {
alert('You must allow popups for this map to work.');
}
PS:如果您使用的是jQuery,则很容易显示div并将div的内容替换为帖子的结果。