Js opener usage details

  • 2020-03-30 01:20:21
  • OfStack

In JS, window.opener is just a reference to the parent window of the pop-up window. Such as:
In a.html, a new window b.html is displayed by clicking the button window.open. Then in b.html, you can reference a.html by window.opener (omitted as opener), including objects such as document of a.html, and manipulate the contents of a.html.
If the reference fails, null is returned. So before calling the opener object, determine if the object is null, or you'll get a "object is empty or not" JS error.

example
Opener. HTML


<html>
<body>
<form name=form1>
<input type=text name=inpu >
<input type=button  onclick="javascript:window.open('back2opener.html?toname=opener.form1.inpu');">
</form>
</body>
</html>

Back2opener. HTML

<html>
<body>
<form name=form1>
<input type=text name=inpu >
<a class=under href=# onclick="{opener.document.form1.inpu.value+=' founder ,';}"> add </a>
</form>
</body>
</html>

JS code:
Window. The open ();
When the payment is successful, the payment success interface of the payment platform needs to be closed, and the payment success page of the client should be loaded on the client side. JS code:
Window. Opener. Location. Href = url; Window. The close ();


Related articles: