Window.open + href заменить и открыть в новом окне, но не используя целевой _blank - PullRequest
1 голос
/ 13 мая 2011

я застрял на чем-то, где я хочу, чтобы ссылки Test 1 и Test 2 открывались в новом окне, not target = _blank в новом окне, поэтому всплывающее окно неоткрыть как вкладку в Firefox и т. д. "href" в javascript должен заполнить href # в ссылках Тест 1 и Тест 2.Что я делаю не так с этим, чтобы я также мог открыть поп в новом окне, но не как цель _blank?

<p><a id="test1" href="#">Test 1</a></p>
<p><a id="test2" href="#">Test 2</a></p>

<script> 
if(chatlink_flag == 'true')
{ 
document.getElementById('test1')window.open.href('http://www.example.com/chat1/open.htm','window1','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no'); 
document.getElementById('test2')window.open.href('http://www.example.com/chat2/open.htm','window2','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no'); 
}else{ 
document.getElementById('test1')window.open.href('http://www.example.com/chat1/closed.htm','window1','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no'); 
document.getElementById('test2')window.open.href('http://www.example.com/chat2/closed.htm','window2','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no'); 
}
</script>

Ответы [ 2 ]

3 голосов
/ 13 мая 2011

Ваш код выглядит нормально, за исключением того, что в нем отсутствует часть "javascript:".

Так что вы можете попробовать сделать строки window.open следующим образом:

document.getElementById('test1').href = "javascript:window.open('http://www.yourpage.com/', 'window1', 'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no')";
0 голосов
/ 13 мая 2011

Я не уверен, что вы ожидали, что этот код будет делать, но следующее должно работать для вас:

<p><a id="test1" href="#" onclick="open_window(1);">Test 1</a></p>
<p><a id="test2" href="#" onclick="open_window(2);">Test 2</a></p>

<script type="text/javascript">

function open_window(id) {
    if (chatlink_flag) {
        window.open('http://www.example.com/chat' + id + '/open.htm','window' + id,'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
    }
    else {
        window.open('http://www.example.com/chat' + id + '/closed.htm','window' + id,'scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
    }
}

</script>
...