English 中文(简体)
HTA Javascript - 这就是为什么在上岸时被拒之门外?
原标题:HTA Javascript - why is object out of scope in onbeforeunload?

这是奇怪的。 我一直在试图从母物体中指定一个儿童物体的功能,但似乎在卸载功能上已经超出了范围。 这些职能指在上载之外的工作,因此只有在上载时才会失败。 我可以通过使儿童成为全球目标来解决这一问题,但我正在努力避免这种情况。 任何人都知道,我的孩子们为什么在上岸时会失去意义? 通知我称,在窗户上载货时,这种功能也是一样的,而且操作得当。 该守则是:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<title>Broken HTA</title>    
<HTA:APPLICATION 
 ID="Broken HTA"
 APPLICATIONNAME="Broken HTA"
 BORDERSTYLE = "flat"
 CAPTION="Yes"
 CONTEXTMENU = "no"
 INNERBORDER = "no"
 MAXIMIZEBUTTON = "no"
 MINIMIZEBUTTON = "yes"
 NAVIGABLE = "No"
 SCROLL = "auto"
 SCROLL FLAT = "Yes"
 SELECTION="no"
 SYSMENU="yes"
 SHOWINTASKBAR="yes"
 SINGLEINSTANCE="yes"
 VERSION = "1.0"
 BORDER="thick"
 >



<script language="javascript" type="text/javascript">

var myparent;

function windowLaunch()
{
    myparent = new parent();
    myparent.getchildvalue();
    window.onbeforeunload = myparent.getchildvalue;
    window.resizeTo(500, 610);
}

function parent()
{
    this.mychild = new childobject("myinput");
    this.getchildvalue = function()
    {
        var tmpval = this.mychild.returnvalue();
    };

}

function childobject(thename)
{
    this.myprop = thename;
    this.returnvalue = function()
    {
        return (document.getElementById(this.myprop).value);
    };
}

</script>
</head>

<body id="thebody" onload="windowLaunch();">
<div id="outerdiv">
        <span title="This Input Box">My Input:</span><br />
        <input id="myinput" style="width: 290px"/>
</div>
</body>

</html>
问题回答

。 电话myoul.getchild Value(>)是优质的,但一旦您指定myother.getchild Value/code>为手,将称为out of context。 你们可以证明这一点:

var obj = { val: 42, fn: function(){ alert(this.val) } };
    ref = obj.fn;

alert(obj.fn === ref); // true, so expect the following to do the same thing...

obj.fn(); // 42, so far so good
ref(); // undefined. uh oh...

可以通过总结:

...
window.onbeforeunload = function(){ myparent.getchildvalue(); };
...

或具有约束力:

...
window.onbeforeunload = myparent.getchildvalue.bind(myparent);
...




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.