2012-04-19 115 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开在同一个链接窗口。