使用window.open()打开一个页面,如模型弹出窗口 [英] open a page using window.open() like model popup

查看:81
本文介绍了使用window.open()打开一个页面,如模型弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i有一个aspx页面,当我点击按钮时我需要在window.open中打开另一个url页面看起来像弹出窗口(当我点击按钮时我的要求是什么不应启用父页面。当我点击弹出窗口中的提交按钮时,我需要将URL和图像发送到另一个URL,这是父网站页面的一部分。

进程应该如下所示:





parentpage1.aspx(www.xyz.com/parentpage1.aspx)------->弹出窗口页面(www.123.com/child.aspx)----->

parentpage2.aspx(www.xyz.com/parentpage2.aspx)





弹出窗口页面需要在window.open中打开,后台应该禁用



其实我是尝试使用灯箱,但它不起作用。

我尝试使用模型弹出窗口,但我无法将数据从弹出窗口发送到页面(数据只是网址)

 var navUrl ='<% =会话[  ReturnUrl] %> '+?Qty =+ qty +'& ThumbnailUrl ='+'< span class =code-pagedirective><% = ViewState [ 缩略图 ] %> '+& ItemNumber =+'<% = ViewState [ 文档] %> '+& Action =+'< ;% = ViewState [ 操作] %GT; '; 

window.opener.location.href = navUrl;



这里重要的东西是我发送的URL如下所示:

< br /> 
http:// localhost:56595 / Success.aspx?数量= 1& amp; ThumbnailUrl = http://honnex1-pc/JesusChristImg/pdfTojpg/LivingWater_LF1110201321117902.jpg& amp ; ItemNumber = D20131011153145960& amp; Action = Create



提前致谢,

问候,

Neimish Varaprasad。 Suggala

解决方案



<前lang =Javascript> var navUrl = ' <%= Session [ReturnUrl]%>' + ?Qty = + qty + ' & ThumbnailUrl =' + ' <%= ViewState [缩略图]%>' + & ItemNumber = + ' < %= ViewState [Document]%>' + & Action = + ' <%= ViewState [Action]%>';
window .opener。 location .href = navUrl;



上述代码在您进行回发之前不会设置查询字符串参数的值。



现在,您要指定父页面的href。回发后,您将不得不刷新父页面。我认为这是一种错误的方法。



符合您的要求:



您的要求是禁用父页面,只要子页面保持打开状态。基本上这些弹出窗口称为模态弹出窗口。使用window.open()方法打开一个窗口默认情况下不禁用父页面。在这种情况下,你将不得不处理很多事情。禁用父窗口,打开子窗口,处理子窗口上的焦点,以便用户永远不会失去焦点并留在页面上等。一个简单的解决方案是使用JQuery插件将外部内容加载到模态div中。之后,您可以从同一页面操作DOM元素。您可以使用以下方法之一:



Magnific Popup [ ^ ]



bPopup [ ^ ]



我希望它有所帮助。


嘿那里,


我为你创建了一个例子,我希望这就是你要找的东西:

在这个例子中,我有两个页面,ParentTest1。 aspx和ParentTest2.aspx,以及将在弹出窗口中打开的页面是MyPopup.aspx,



好​​的我有一个Button和JavaScript来打开ParentTest1中的弹出窗口。 aspx:

ParentTest1.aspx:

 <   asp:按钮    runat   =  server    id   =  BtnPopUp    text   = 打开弹出窗口    onclientclick   = 返回OpenPopup();     xmlns:asp   = #unknown    /  >  



  function  OpenPopup(){
var returnValue = window .showModalDialog( MyPopup.aspx?Qty = 1& ThumbnailUrl = http://honnex1-pc/JesusChristImg/pdfTojpg/LivingWater_LF1110201321117902.jpg& ItemNumber = D20131011153145960&操作=创建 高度:500,宽度:500;);
窗口 lo阳离子 = returnValue.MyURL;

return false ;
}



我有一个提交按钮和JavaScript函数,可以在MyPopup.aspx页面上返回打开ParentTest2.aspx的URL。

MyPopup.aspx:

 <   asp:button     runat   =  server    id   =  BtnSubmit    text   = 提交    onclientclick   = 返回OK();    xmlns:asp   = #unknown    /  >  



 < span class =code-keyword> function  OK(){
var vReturnValue = new Object();
vReturnValue.MyURL = ParentTest2.aspx?ID = AnyValue;
window .returnValue = vReturnValue;
window .close();
return false ;
}





尝试一下,如果有帮助请告诉我。



Azee ...


hi azee,

i只需设计实际上我的代码正在使用window.open()但我有一个要求只有带有禁用父页面的window.open(),我的要求几乎就像jafar所说的那样..

谢谢你Azee和Jafar。 Jafar如果可能的话请告诉我我必须做什么(禁用父窗口,打开子窗口,处理子窗口的焦点)..

谢谢

Neimish varaprasad.Suggala


hi,
i have an aspx page and when i click on button i need to open another url's page in window.open whick looks like a popup( what exactly my requirement is when i click on button the parent page should not be enable). And when i click on submit button on my popup window i need to send url and image to the another url which is a part of parent website page.
process should look like here:


parentpage1.aspx(www.xyz.com/parentpage1.aspx) -------> popup window page(www.123.com/child.aspx) ----->
parentpage2.aspx(www.xyz.com/parentpage2.aspx)


Popup window page is need toopen in window.open and background should disable

actually i am trying with lightbox also but it's not working.
And i tried with model popup also but i am unable to send data from popup to page(the data is url only )

var navUrl = '<%=Session["ReturnUrl"] %>' + "?Qty=" + qty + '&ThumbnailUrl=' + '<%=ViewState["Thumbnail"]%>' + "&ItemNumber=" + '<%=ViewState["Document"]%>' + "&Action=" + '<%=ViewState["Action"]%>';

       window.opener.location.href = navUrl;


here the importent thing is the URL i am sending is like this below:

<br />
http://localhost:56595/Success.aspx?Qty=1&amp;ThumbnailUrl=http://honnex1-pc/JesusChristImg/pdfTojpg/LivingWater_LF1110201321117902.jpg&amp;ItemNumber=D20131011153145960&amp;Action=Create


Thanks in advance,
Regards,
Neimish Varaprasad.Suggala

解决方案

Hi,

var navUrl = '<%=Session["ReturnUrl"] %>' + "?Qty=" + qty + '&ThumbnailUrl=' + '<%=ViewState["Thumbnail"]%>' + "&ItemNumber=" + '<%=ViewState["Document"]%>' + "&Action=" + '<%=ViewState["Action"]%>'; 
window.opener.location.href = navUrl;


The above code will not set the values of querystring parameters until you make a postback.

Now, you are specifying the href of the parent page. After the postback you will have to refresh the parent page. I think it is a wrong approach.

Coming to your requirement:

Your requirement is to disable the parent page as long as the child page is kept opened. Basically these popups are known as modal popups. Opening a window using window.open() method do not disable the parent page by default. You will have to handle a lot of things in that case. Disabling parent window, opening child window, handling the focus on the child window so that the user never lose the focus and stay on the page etc. A simple solution would be to use JQuery plugin that loads the external contents into the modal div. After that you can manipulate the DOM elements from the same page. You can use one of these:

Magnific Popup[^]

bPopup[^]

I hope it helps.


Hey there,

I have created an example for you, I hope this is what you were looking for:
In this example, I have two Pages, ParentTest1.aspx and ParentTest2.aspx, and the page that will open in popup is MyPopup.aspx,

Ok I have a Button and the JavaScript to open the popup in ParentTest1.aspx:
ParentTest1.aspx:

<asp:button runat="server" id="BtnPopUp" text="Open Popup" onclientclick="return OpenPopup(); " xmlns:asp="#unknown" />


function  OpenPopup() {
             var returnValue = window.showModalDialog("MyPopup.aspx?Qty=1&ThumbnailUrl=http://honnex1-pc/JesusChristImg/pdfTojpg/LivingWater_LF1110201321117902.jpg&ItemNumber=D20131011153145960&Action=Create", "", "Height:500, width:500;");
             window.location = returnValue.MyURL;
             
             return false;
         }


I have a button to submit and JavaScript function to return a URL to open ParentTest2.aspx on MyPopup.aspx page.
MyPopup.aspx:

<asp:button runat="server" id="BtnSubmit" text="Submit" onclientclick="return OK();" xmlns:asp="#unknown" />


function OK() {
             var vReturnValue = new Object();
             vReturnValue.MyURL = "ParentTest2.aspx?ID=AnyValue";
             window.returnValue = vReturnValue;
             window.close();
             return false;
         } 



Try it and let me know if it helps.

Azee...


hi azee,
i need just design only actually my code is working with window.open() but i have a requirement only window.open() with disabling parent page, my requirement is almost like what jafar has said..
Thank u Azee and Jafar. Jafar if possible can you please tell me what i have to do for this ( Disabling parent window, opening child window, handling the focus on the child window)..
Thanks
Neimish varaprasad.Suggala


这篇关于使用window.open()打开一个页面,如模型弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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