2011-11-16 3 views
0

내가 masterpagecode, 모든 어린이 페이지 내 자바 스크립트를 실행하려고 :모든 하위 페이지에서 js를 실행하는 방법은 무엇입니까?

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WindowonUnload.Site1" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <asp:ContentPlaceHolder ID="head" runat="server"> 

    </asp:ContentPlaceHolder> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 
     <script> 
      //window.addEventListener('unload', function() { alert('hahaha'); }); 
      window.onunload = function() { 
       alert('from webf master'); 
      } 
    </script> 
     </asp:ContentPlaceHolder> 
    </div> 
    </form> 
</body> 
</html> 

childpage : 내가 잘못

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" 
    CodeBehind="WebForm1.aspx.cs" Inherits="WindowonUnload.WebForm1" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 

</asp:Content> 

을 뭐하는 거지?

+0

시도를 당신의 자바 스크립트 코드를 넣습니다. –

답변

0

은 MasterPage <Head> 태그 안에 마스터 페이지의 헤더 태그 내부에 스크립트를 추가

<head runat="server"> 
    <title></title> 
    <script type="text/jscript"> 
      window.onunload = function() {alert('from webf master');} 
    </script> 
</head> 
0

스크립트 태그를 마스터 페이지의 콘텐츠 자리 표시 자 외부에 배치 해보십시오.

0

이 시도 :

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WindowonUnload.Site1" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <head> 
     <script> 
      window.onunload = function() { 
       alert('from webf master'); 
      } 
     </script> 
    </head> 
    <asp:ContentPlaceHolder ID="head" runat="server"> 

    </asp:ContentPlaceHolder> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 

     </asp:ContentPlaceHolder> 
    </div> 
    </form> 
</body> 
</html> 
관련 문제