danielivanov2
asked on
window.opener does not work in https, but ok in http
Hello, I have a strange situation related to javascript window.opener.
I have 2 websites hosted in the same platform, UAT&PRD.
The only difference, beside the domain, is that UAT is on http, and PRD on https.
The below script works fine in UAT, but in PRD (https) I have the following error:
Error:
C#
javascript
To be mentioned that both PRD pages (opener and popup) are under https://
Thanks
I have 2 websites hosted in the same platform, UAT&PRD.
The only difference, beside the domain, is that UAT is on http, and PRD on https.
The below script works fine in UAT, but in PRD (https) I have the following error:
Error:
TypeError: window.opener.document.getElementById(...) is null
C#
System.Text.StringBuilder sbScript = new System.Text.StringBuilder();
sbScript.Append(@"setTimeout(function(){closePopup()},2000);window.opener.document.getElementById('" + anchorId + "').click();");
if (!ClientScript.IsStartupScriptRegistered("scriptTest"))
ClientScript.RegisterStartupScript(this.GetType(), "scriptTest", sbScript.ToString(), true);
javascript
function closePopup(){
var opener = null;
if (window.dialogArguments) // Internet Explorer supports window.dialogArguments
{
opener = window.dialogArguments;
}
else // Firefox, Safari, Google Chrome and Opera supports window.opener
{
if (window.opener)
{
opener = window.opener;
}
}
// write you code and refer "opener"
window.close();
};
To be mentioned that both PRD pages (opener and popup) are under https://
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Unfortunately, same result, ok in UAT, not ok in PRD, same javascript error, which is telling me that some sort of security is preventing this script to work.
I forgot to include in initial code the anchorId tag, in opener page:
Below the script generated by Firebug, that is causing the error:
I forgot to include in initial code the anchorId tag, in opener page:
<a id="anchorId" runat="server" onclick="return true" onserverclick="postback"></a>
Below the script generated by Firebug, that is causing the error:
TypeError: window.opener.document.getElementById(...) is null
<script type="text/javascript">
//<![CDATA[
(function() {var fn = function() {$get("ToolkitScriptManager1_HiddenField").value = '';Sys.Application.remove_init(fn);};Sys.Application.add_init(fn);})();setTimeout(function(){window.opener.document.getElementById(' MainContentPlaceHolder_anchorId').click();closePopup()},2000);(function() {var fn = function() {Sys.Extended.UI.ModalPopupBehavior.invokeViaServer('mpeTrainingFinished', true); Sys.Application.remove_load(fn);};Sys.Application.add_load(fn);})();Sys.Application.initialize();
ASKER
I have finally solved it, the anchorId should have been ctl00_MainContentPlaceHold er_anchorI d and not MainContentPlaceHolder_anc horId, as initially set.
however, I will set the second answer as solution, as it is correcting my code
Thanks
however, I will set the second answer as solution, as it is correcting my code
Thanks
ASKER
The solution is posted in the last comment, however this post is showing the correct way to handle my script
Perhaps it is a security issue. Can you try lowering the security while testing?