Google chrome gives this javascript error
Uncaught TypeError: Object javascript:__doPostBack('ctl00$MainContentPlaceHolder$lnkBtnHidden','') has no method 'click'
while executing this line
window.opener.document.getElementById('ctl00_MainContentPlaceHolder_lnkBtnHidden').click();
I have verified that the control is in the opener page and that the ID of the button is same as well, but window.opener.document.getElementById('ctl00_MainContentPlaceHolder_lnkBtnHidden') returns this, rather than an object:
javascript:__doPostBack('ctl00$MainContentPlaceHolder$lnkBtnHidden','')
This happens only in Chrome…
EDIT: The code used to open the window is like this:
win= window.open('/PageName.aspx?qs=qsValue','','scrollbars=1,width=1000,height=950');
win.moveTo(0,0);
Don’t be confused by the returned
javascript:__doPostBack('ctl00$MainContentPlaceHolder$lnkBtnHidden','')some browsers use the href-attribute of an hyperlink as a string-representation of the <a/>-element.
The returned object still is the element-object.
I already wrote inside the comment that click() in (my) Chrome doesn’t work on a-elements. It works for me in
input[type=submit], but maybe your chrome-version doesn’t support it. But that doesn’t matter as long as you can’t rely on the fact that click() works anywhere.When your approach by using dispatchEvent() doesn’t work, I guess your implementation is wrong, here an example-function:
What else: you should move the call of
javascript:__doPostBack()from the href-attribute to the onclick-attribute. Otherwise there is no guarantee that the function gets called(depending on the browser).see an example: http://fiddle.jshell.net/doktormolle/swR59/show/
opener-source: http://jsfiddle.net/doktormolle/swR59/
popup-source: http://jsfiddle.net/doktormolle/vHwCr/