2012-04-19 99 views
1

我的Javascript不是最好的,而且我的問題是在同一個窗口打開鏈接而不是新的彈出窗口。Javascript - 打開一個鏈接

在我的html,我有以下鏈接

<a href="javascript:go_registerParamList('<%=appendStr%>');">Open An Account</a> 

的JavaScript的 'go_registerParamList' 是:提前

function go_registerParamList(paramList) { 
    if (self.opener == null) { 
     var base_window = self; 
    } else { 
     var base_window = self.opener; 
    } 
    if (paramList == '') { 
     var link = 'https://${accountUrl}?action=go_register_popup&area=SK&button=openregbutton&promo=new_regbutton_en&crea=img&bus_channel=SK'; 
    } else { 
     var link = 'https://${accountUrl}?action=go_register_popup&area=SK&button=openregbutton&promo=new_regbutton_en&crea=img' + '&' + paramList; 
    } 

    base_window.open(link, "pp_registration", "width=642, height=620, scrollbars=no, menubar=no, status=no, scrollbars=no, resizable=yes,screenX=5, screenY=5, left=5, top=5"); 
} 

感謝。

+0

http://stackoverflow.com/questions/267704/javascript-open-new-page-in-same-window – TRR 2012-04-19 10:55:56

回答

1

.open()方法打開一個新窗口。

相反,你可以這樣做:

window.location = link; 

所以:

function go_registerParamList(paramList) 
{ 
    var link; 
    if(paramList == '') 
    { 
     link = 'https://${accountUrl}?action=go_register_popup&area=SK&button=openregbutton&promo=new_regbutton_en&crea=img&bus_channel=SK'; 
    } 
    else 
    { 
     link = 'https://${accountUrl}?action=go_register_popup&area=SK&button=openregbutton&promo=new_regbutton_en&crea=img&' + paramList; 
    } 
    window.location = link; 
} 
0

使用window.open(URL,名稱,規格,替換)名稱爲 「_self」

window.open(link, "_self" , "width=642, height=620, scrollbars=no, menubar=no, status=no, scrollbars=no, resizable=yes,screenX=5, screenY=5, left=5, top=5"); 
0
Before you call the base_window.open() method try to alert the link variable. If its 
okay then you may not have problem with that. 

Thanks. 
2

JavaScript函數:

function openInSameWindow(evt) { 
    window.location=evt; 
} 

HTML超鏈接在同一窗口中打開:

<a onclick="openInSameWindow('http://google.com')">Click to open in same window</a> 

你可以調用函數openInSameWindow開在同一個鏈接窗口。