2013-06-04 40 views
0
<script language=JavaScript> 
winRef = new Object(); 
winRef.closed = true; 
</script> 

<form name=f1 id=f1> 
<input type=button name=b1 id=b1 value="New window" 
onClick="winRef=window.open('http://www.google.com/','myNewWindow', 
    'left=15,top=15,width=510,height=420,toolbar=1,menubar=1,resizable=1,status=1'); 
    winRef.focus()"> 

<input type=button name=b2 id=b2 value="Close the window" 
onClick="if(!winRef.closed)winRef.close();"> 

<input type=button name=b3 id=b3 value="Check: is it closed?" 
onClick="alert(winRef.closed ? 'It\'s CLOSED!':'It\'s still OPEN!');"> 

<input type=button name=b4 id=b4 value="Change new window URL" 
onClick="winRef.location.href('http://example.com/' + winRef.location.href)"> 
</form> 

該代碼在新窗口中打開google,然後檢查它是否打開並關閉它。我應該如何改變它的名字是「http://example.com/?url=http://www.google.com/」 我需要把我的網站的網址在打開的窗口URLJavaScript如何打開新窗口然後更改其URL?

+2

'href'不是一個函數 – SLaks

回答

0

這裏的前面是代碼:

<script language="javascript"> 
var strWindowFeatures = "menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=200,height=200"; 
var nome='nameofme'; 
function vamos(url1){ 
    win = window.open(url1,nome,strWindowFeatures); 
    win.focus(); 
    // If the window opened successfully (e.g: not blocked) 
    if (win) { 
     win.onload = function() {//onload can be blocked by the brower 
      win.location.href='http://www.bing.com'; 
     }; 
    } 
    setTimeout("win.location.href='http://www.bing.com'",4000);//change the href after 4 second 
    win.focus(); 
    window.history.replaceState('Object', 'Title', '?http://www.bing.com'); 
    setTimeout("window.history.replaceState('Object', 'Title', '?http://www.fava.com')",4000);//after 4 sec 
} 
</script> 
<button id="dd" onClick="vamos('http://www.google.com')">but</button> 

這裏jsfiddle,保持它在請注意,在小提琴中,window.history.replaceState將不起作用

+0

這很好,但我真正需要的是重定向後的鏈接,例如:www.google.com打開後被重定向到www.google.com.uk,所以我需要鏈接www.example.com後的最後一個鏈接/?www .google.com.uk – user2443940

+0

@ user2443940您需要在一段時間後或剛剛打開新窗口時重定向用戶? –

+0

但如何把我的鏈接與目前的鏈接? – user2443940

相關問題