常用效果的实现(Javascript的子父页访问、函数调用)

实现过程:
父页面
打开新窗口的javascript函数为:
    function openpage(htmlurl) 
    
{
        
var newwin=window.open(htmlurl,"newWin","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,menubar=no,resizable=yes,top=100,left=200,width=650,height=300"
);
        newwin.focus();
        
return false
;
    }

    
</script>
在按钮中调用:
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return openpage('child.aspx');"/>

子页面
绑定gridview的数据源,并在它的RowDataBound事件里写代码如下:
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    
{
        
string = "window.opener.document.getElementById('textbox1').value='" + e.Row.Cells[1].Text + "'; window.close();"
;
        
if (e.Row.RowType !=
 DataControlRowType.Header)
        
{
            e.Row.Attributes.Add(
"ondblclick"s);//
双击选择
            
//当鼠标移到的时候设置该行颜色为"", 并保存原来的背景颜色

            e.Row.Attributes.Add("onmouseover""currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C0C0FF';this.style.cursor='hand';");
            
//当鼠标移走时还原该行的背景色

            e.Row.Attributes.Add("onmouseout""this.style.backgroundColor=currentcolor");
        }

    }
说明:通过window.open打开新页面,两个页面之前便有了一种父子关系。子页通过opener可以访问父页(控件及写在父页的js函数),父页同样通过sub可以访问子页。如在父页有个js函数sayhello(),在子页中只需要opener.sayhello()便可以调用了

转自:http://blog.sina.com.cn/s/blog_4efce4d10100cimg.html

原文地址:https://www.cnblogs.com/bicabo/p/1438364.html