基本的Javascript问题 [英] Basic Javascript Question

查看:48
本文介绍了基本的Javascript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在尝试做一些非常简单的事情。我有一个页面MainPage.aspx和一个弹出窗口Popup.aspx。

。当

用户点击弹出窗口中的链接按钮时,我希望在Popup.aspx中进行一些服务器端处理,

然后有弹出窗口关闭,并有

MainPage.aspx回发到服务器。但是我很难确定客户端javascript

Popup.aspx应该在服务器端进行处理后进行渲染

处理。是否有任何样品或物品

演示如何做到这一点?我一直得到对象

预期在CloseChildWindow():


script.js

---------------------- ---------

var PopUp;


//从MainPage.aspx调用

函数OpenPopup( id,mode,eid)

{

var url ="" ;;

url + =" Controls / PopUp.aspx? " ;;

url + =" FormName =" + document.forms [0] .name;

url + ="& id =" + id;

url + ="& m =" ; +模式;

url + ="& eid =" + eid;


var width = 250;

var height = 150;


var str ="" ;;

str + =" toolbars = no," ;;

str + =" status = no," ;;

str + =" resizable = 0," ;;

str + =" scrollbars = 0," ;;

str + =" width =" + width +"," ;;

str + =" height ="如果(window.screen){

var ah = screen.availHeight - 30;
$ $ + $ b b $ b var aw = screen.availWidth - 10;


var xc =(aw - width)/ 2;

var yc =(ah - height )/ 2;


str + =",left =" + xc +",screenX =" + xc;

str + =",top =" + yc +",screenY =" + yc;

}


PopUp = window.open(url,''EmailList'',str);

}


函数CloseChildWindow(id,postBack)

{

调试器;

PopUp.close( );

if(postBack)

__doPostBack(id,'''');

}


我在Popup.aspx中的代码是


< script language =" JavaScript">

<! -


window.onload = window_onload();


函数window_onload(){

window.opener.CloseChildWindow(' 'a'',true);

}


// - >

< / script>


任何帮助将不胜感激!谢谢。

解决方案

除了所有明显的东西,如域名权利和案件

sensitiv试图寻找这个:


对于IE中公开的JavaScript(由其他程序看到),它必须是在html标题中声明的


如果我正确地解释你的JavaScript,看起来你的脚本是

应该在PostBack之后关闭窗口。

a回发后浏览器中的页面与PostBack之前的浏览器中的页面不同。

它可能是相同的HTML文档,但内存是新实例不是与旧的内存相同的
- HTTP是无状态的。对于浏览器来说,它是一个全新的页面。因此,

内存中不再存在指向子窗口的窗口对象引用。使用相同的变量名称

没有。


-

HTH,


Kevin Spencer

Microsoft MVP

..Net开发人员
http://www.takempis.com

跟随者和贷款人都不是。

" Mark Fox" <在** @ solelsoftware.com>在留言中写道

news:07 **************************** @ phx.gbl ... < blockquote class =post_quotes>你好,

我正在尝试做一些非常简单的事情。我有一个页面MainPage.aspx和一个弹出窗口Popup.aspx。当用户点击弹出窗口中的链接按钮时,我希望在Popup.aspx中进行一些服务器端处理,然后关闭弹出窗口,并有
MainPage.aspx回发到服务器。但是我无法确定Popup.aspx在进行服务器端处理后应该呈现什么样的客户端javascript。有没有样品或文章可以证明如何做到这一点?我一直得到对象
预期在CloseChildWindow():

script.js
------------------------------ -
var PopUp;

//从MainPage.aspx调用
函数OpenPopup(id,mode,eid)
{
var url =" " ;;
url + =" Controls / PopUp.aspx?" ;;
url + =" FormName =" + document.forms [0] .name;
url + ="& id =" + id;
url + ="& m =" +模式;
url + ="& eid =" + eid;

var width = 250;
var height = 150;
var str ="" ;;
str + =" toolbars = no," ;;
str + =" status = no," ;;
str + =" resizable = 0," ;;
str + =" scrollbars = 0," ;;
str + =" width =" + width +"," ;;
str + =" height =" + height +"," ;;

if(window.screen){
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc =(aw - width)/ 2;
var yc =(ah - height)/ 2;

str + =",left = " + xc +",screenX =" + xc;
str + =",top =" + yc +",screenY =" + yc;
}

PopUp = window.open(url,''EmailList'',str);


函数CloseChildWindow(id ,postBack)
{
调试器;
PopUp.close();
if(postBack)
__ doPostBack(id,'''');
}我在Popup.aspx中的代码是

< script language =" JavaScript">
<! -

window.onload = window_onload();

函数window_onload(){
window.opener.CloseChildWindow('''',true);
}

// - >
< / script>

任何帮助将不胜感激!谢谢。



您好


如果我帮你...


在弹出窗口中进行处理

将一个脚本返回到弹出窗口,该窗口在开启器中调用某些方法


window.opener。 document.forms [0] .mySubmitBtn.click(); //这将点击一个名为mySubmitBtn的
提交按钮

或者在父窗口中调用一个函数(开启者)

window.opener.FUNCTIONNAME( );

window.close(); //关闭孩子


-

最好的问候

Vidar Petursson

==============================

Microsoft Internet Client&控制MVP

==============================

"马克福克斯 <在** @ solelsoftware.com>在留言中写道

news:07 **************************** @ phx.gbl ... < blockquote class =post_quotes>你好,

我正在尝试做一些非常简单的事情。我有一个页面MainPage.aspx和一个弹出窗口Popup.aspx。当用户点击弹出窗口中的链接按钮时,我希望在Popup.aspx中进行一些服务器端处理,然后关闭弹出窗口,并有
MainPage.aspx回发到服务器。但是我无法确定Popup.aspx在进行服务器端处理后应该呈现什么样的客户端javascript。有没有样品或文章可以证明如何做到这一点?我一直得到对象
预期在CloseChildWindow():

script.js
------------------------------ -
var PopUp;

//从MainPage.aspx调用
函数OpenPopup(id,mode,eid)
{
var url =" " ;;
url + =" Controls / PopUp.aspx?" ;;
url + =" FormName =" + document.forms [0] .name;
url + ="& id =" + id;
url + ="& m =" +模式;
url + ="& eid =" + eid;

var width = 250;
var height = 150;
var str ="" ;;
str + =" toolbars = no," ;;
str + =" status = no," ;;
str + =" resizable = 0," ;;
str + =" scrollbars = 0," ;;
str + =" width =" + width +"," ;;
str + =" height =" + height +"," ;;

if(window.screen){
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc =(aw - width)/ 2;
var yc =(ah - height)/ 2;

str + =",left = " + xc +",screenX =" + xc;
str + =",top =" + yc +",screenY =" + yc;
}

PopUp = window.open(url,''EmailList'',str);


函数CloseChildWindow(id ,postBack)
{
调试器;
PopUp.close();
if(postBack)
__ doPostBack(id,'''');
}我在Popup.aspx中的代码是

< script language =" JavaScript">
<! -

window.onload = window_onload();

函数window_onload(){
window.opener.CloseChildWindow('''',true);
}

// - >
< / script>

任何帮助将不胜感激!谢谢。



Hello,

I am attempting to do something very simple. I have
a page MainPage.aspx and a popup window Popup.aspx. When
users click on the linkbutton in the popup window I am
looking to do some server side processing in Popup.aspx,
then have the popup window close, and have the
MainPage.aspx do a postback to the server. But I am
having trouble determining what client side javascript
Popup.aspx should render after it does its server side
processing. Are there any samples or articles tha
demonstrate how to do this? I keep getting "Object
Expected" in CloseChildWindow():

script.js
-------------------------------
var PopUp;

// Called from MainPage.aspx
function OpenPopup(id, mode, eid)
{
var url = "";
url += "Controls/PopUp.aspx?";
url += "FormName=" + document.forms[0].name;
url += "&id="+ id;
url += "&m=" + mode;
url += "&eid="+ eid;

var width = 250;
var height = 150;

var str = "";
str += "toolbars=no,";
str += "status=no,";
str += "resizable=0,";
str += "scrollbars=0,";
str += "width=" + width + ",";
str += "height=" + height + ",";

if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}

PopUp = window.open( url, ''EmailList'', str );
}

function CloseChildWindow(id, postBack)
{
debugger;
PopUp.close();
if (postBack)
__doPostBack(id,'''');
}

The code I have in Popup.aspx is

<script language="JavaScript">
<!--

window.onload=window_onload();

function window_onload() {
window.opener.CloseChildWindow(''a'', true);
}

//-->
</script>

Any help would be appreciated! Thanks.

解决方案

Hi, besides from all the obvious things like domain rights, and case
sensitiv try to look for this:

For JavaScript to be public(seen by other programs) in IE, It has to be
declared in the html header.


If I interpret your JavaScript correctly, it looks like your script is
supposed to close the window AFTER a PostBack. The page in the browser after
a postback is not the same page that was in the browser BEFORE the PostBack.
It may be the same HTML document, but the memory of the new instance is not
the same as the memory of the old - HTTP is stateless. To the browser, it is
a whole new page. Therefore, there is no longer a window object reference in
memory pointing to the child window. Using the same variable name does
nothing.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.
"Mark Fox" <in**@solelsoftware.com> wrote in message
news:07****************************@phx.gbl...

Hello,

I am attempting to do something very simple. I have
a page MainPage.aspx and a popup window Popup.aspx. When
users click on the linkbutton in the popup window I am
looking to do some server side processing in Popup.aspx,
then have the popup window close, and have the
MainPage.aspx do a postback to the server. But I am
having trouble determining what client side javascript
Popup.aspx should render after it does its server side
processing. Are there any samples or articles tha
demonstrate how to do this? I keep getting "Object
Expected" in CloseChildWindow():

script.js
-------------------------------
var PopUp;

// Called from MainPage.aspx
function OpenPopup(id, mode, eid)
{
var url = "";
url += "Controls/PopUp.aspx?";
url += "FormName=" + document.forms[0].name;
url += "&id="+ id;
url += "&m=" + mode;
url += "&eid="+ eid;

var width = 250;
var height = 150;

var str = "";
str += "toolbars=no,";
str += "status=no,";
str += "resizable=0,";
str += "scrollbars=0,";
str += "width=" + width + ",";
str += "height=" + height + ",";

if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}

PopUp = window.open( url, ''EmailList'', str );
}

function CloseChildWindow(id, postBack)
{
debugger;
PopUp.close();
if (postBack)
__doPostBack(id,'''');
}

The code I have in Popup.aspx is

<script language="JavaScript">
<!--

window.onload=window_onload();

function window_onload() {
window.opener.CloseChildWindow(''a'', true);
}

//-->
</script>

Any help would be appreciated! Thanks.



Hi

If I get you right...

Do the processing in the popup
Return a script to the popup that calls some method(s) in the opener

window.opener.document.forms[0].mySubmitBtn.click(); // This will click a
submit button named mySubmitBtn
Or call a function in parent window(opener)
window.opener.FUNCTIONNAME();
window.close();// Close child

--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
"Mark Fox" <in**@solelsoftware.com> wrote in message
news:07****************************@phx.gbl...

Hello,

I am attempting to do something very simple. I have
a page MainPage.aspx and a popup window Popup.aspx. When
users click on the linkbutton in the popup window I am
looking to do some server side processing in Popup.aspx,
then have the popup window close, and have the
MainPage.aspx do a postback to the server. But I am
having trouble determining what client side javascript
Popup.aspx should render after it does its server side
processing. Are there any samples or articles tha
demonstrate how to do this? I keep getting "Object
Expected" in CloseChildWindow():

script.js
-------------------------------
var PopUp;

// Called from MainPage.aspx
function OpenPopup(id, mode, eid)
{
var url = "";
url += "Controls/PopUp.aspx?";
url += "FormName=" + document.forms[0].name;
url += "&id="+ id;
url += "&m=" + mode;
url += "&eid="+ eid;

var width = 250;
var height = 150;

var str = "";
str += "toolbars=no,";
str += "status=no,";
str += "resizable=0,";
str += "scrollbars=0,";
str += "width=" + width + ",";
str += "height=" + height + ",";

if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}

PopUp = window.open( url, ''EmailList'', str );
}

function CloseChildWindow(id, postBack)
{
debugger;
PopUp.close();
if (postBack)
__doPostBack(id,'''');
}

The code I have in Popup.aspx is

<script language="JavaScript">
<!--

window.onload=window_onload();

function window_onload() {
window.opener.CloseChildWindow(''a'', true);
}

//-->
</script>

Any help would be appreciated! Thanks.



这篇关于基本的Javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆