开发者

JavaScript question related to the use of ' and "

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜