0
my_window.document.write(' 
  <script type="text/javascript"> 
    function redirect(linkid) { 
      opener.location.href=linkid;
      window.close();
    }
  </script>
  <h1>Hello</h1>
  <p>Thank you.If you accidentally closed our website click 
  <a href="javascript:redirect('http://google.com')">here</font></a> 
  to go back to our  website</p>
'); 

This is my piece of code to close a already opened pop up window by redirecting it to google.com. I think there is some problem with matching the apostrophes ' and "... how to code with (' (" (' ') ") ')... is this correct? please help me with this.

Please help me with the necessary changes wherever required.

2 Answers 2

3

Yes, you need to escape the single quotes with a backslash:

... redirect(\'http://google.com\') ...

In addition keep in mind that popping up a window like that will most likely be blocked by popup blockers... apart from being a questionable practice.

Sign up to request clarification or add additional context in comments.

1 Comment

i was able to launch pop up window with just a message. but if i want the pop up to have a link in it, i want to redirect to some page and close the pop up window. so i decided to use javascript but it is creating problems.
0

Please read the formatting for your code -- select it all and hit ctrl + k.

Also, I suggest you need to use a backslash infront of the single quotes within the single quotes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.