meks
meks

Reputation: 807

How to redirect parent page using javascript

I want to ask you how to redirect parent page to a certain url from a pup up page? I tried several options as parent or opener and nothing is working. Please help me to understand what is wrong.

here is the code i used:

<html>
<head>
<script>
  function openWin(){
       myWindow=window.open('','','width=200,height=100');
       myWindow.document.write("<p>This is 'myWindow'</p> <button onclick=\"window.opener.location.href = ='http://www.google.com'; window.close();\">refresh</button>");
       myWindow.focus();
  }
</script>
</head>
<body>

   <input type="button" value="Open window" onclick="openWin()" />

 </body>
 </html>

Upvotes: 1

Views: 1050

Answers (1)

Vedran Šego
Vedran Šego

Reputation: 3765

You have an error in your code. Should be

myWindow.document.write("<p>This is 'myWindow'</p> <button onclick=\"window.opener.location.href = 'http://www.google.com'; window.close();\">refresh</button>");

i.e., remove the extra = before 'http://www.google.com'.

Upvotes: 2

Related Questions