การเรียกใช้งานฟังก์ชันจาวาสคริปในหน้าอื่น

หน้าหลัก

<html>
<head>
<script LANGUAGE="
JavaScript" TYPE="text/javascript">

   
function openWindow(){
      WREF = window.open("test2.html","test2",'width=550,height=650');
      if(!WREF.opener){ WREF.opener = this.window; }
   }
   
function getValue(val){
      newVal =  5 * val;
      return newVal;
   }
   var globalGetValue = this.getValue;
</script>
</head>
<body>
<a HREF="
javascript:void(0);" onClick="openWindow();">Open the window</a>
</body>
</html>

หน้ารองที่จะเรียกใช้งานฟังก์ชันในหน้าหลัก
<html>
<head>
</head>
<body>
<script LANGUAGE="JavaScript" TYPE="text/javascript">
document.write("This is 5 x 7: " + opener.globalGetValue(7));
</script>
</body>
</html>


ผมกำลังทำงานในลักษณะนี้อะครับ เผื่อคนที่ยังไม่รู้ แต่มันต้องเอาไปประยุกต์อีก นี้เป็นโค้ดต้นแบบ เลยเอามาแบ่งปัน

11 ส.ค. 2552 1 2,550

 น่าจะเอาไปโพสต์ไว้ใน blog นะครับ อยู่บนบอร์ด อีกสักพักคนก็ไม่เห็นแล้ว
#1
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^