Need help with window.opener/window.opener.document
Hi,
I have a page in which if i click a link will pops up a window(which has 2 dropdowns,checkbox and a button).
And when the user selects an option in the dropdown, checks the checkbox and hits the button a new page needs to be populatde in the first page.
For this i used
<a href="javascript:void(0);" onclick="Image_Click()"><asp:button text="common" onclick="btnClick" runat="server"/></a>
i wrote the function image_click using java script as below:
When i open the link in the first or main page.the second page with dropdowns and checkboxes opens and when i select an option and than check the checkbox and proceed .only the first url(www.bookstore.com) page is opened regardless of what i select .This happens in both IE and Firefox.
I tried both single and double quotes everywhere and also used window.opener.document.location and window.opener.location.href and nothing works.
When i tried to run(debug) the aspx page it gives window.opener.document is null or not an object.
i think the issue is that once you do the window.close() method, the window object is destroyed. when you try to referene the opener property of the now NULL (destroyed) object, you get this issue.
to resolve it, before you close() the window, make a variable called "opener" or something and assign it the "window.opener" value. after you close the window, the opener object will still exist and you should be able to redirect it.
1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
var openerObj = window.opener
window.close()
openerObj.document.location.href = "somelocation.com"
1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
var e=document.getElementById("GetName");//GetName is name of dropdown
var opt=e.options[e.selectedIndex].value
if(opt=="Sams")
{
var openerObj=window.opener
window.close();
openerObj.document.location.href="http://www.sams.com";
}
else if(opt==Costco")
{
var openerObj=window.opener
window.close();
openerObj.document.location.href="http://www.coscto.com";
}
elseif
.....
else
{
alert();
Not sure why this doesnot work for me.
When i ran this on the server,running line by line.It gave me an error saying do you want to close the window and then when i hit yes or no it says "Microsoft JScript runtime error: 'document' is null or not an object".
And when i open the url on my local machine it does nothing when i select an option in the dropdown.
Can you please give me some idea why i am returning with this error.
Thanks a Lot
Tekky
}
Originally Posted by aaron.martinas
here's an example:
Code:
var openerObj = window.opener
window.close()
openerObj.document.location.href = "somelocation.com"
right after window.close(), place the line "alert(openerObj)".. what do you get?
1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
Bookmarks