html - Popup window in Javascript - Stack Overflow

In Javascript, I want to open my window.html file in a popup window. But it doesn't display any te

In Javascript, I want to open my window.html file in a popup window. But it doesn't display any text. Just a blank page.

This is index.html:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="style.css" />

  <script language="javascript">
    var newwindow;

    function popit(url){
      newwindow = window.open(
          url, '', "status=yes, height=500; width=500; resizeable=0");
  }
  </script>
</head>
<body>
  <a href="javascript:popit(window.html);">CLICK ME!</a>
</body>
</html>

window.html:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <p>SAMPLE TEXT</p>
</body>
</html>

Why doesn't it display any text?

In Javascript, I want to open my window.html file in a popup window. But it doesn't display any text. Just a blank page.

This is index.html:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="style.css" />

  <script language="javascript">
    var newwindow;

    function popit(url){
      newwindow = window.open(
          url, '', "status=yes, height=500; width=500; resizeable=0");
  }
  </script>
</head>
<body>
  <a href="javascript:popit(window.html);">CLICK ME!</a>
</body>
</html>

window.html:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <p>SAMPLE TEXT</p>
</body>
</html>

Why doesn't it display any text?

Share Improve this question edited Nov 24, 2013 at 19:20 Eric Leschinski 154k96 gold badges422 silver badges337 bronze badges asked Apr 28, 2013 at 14:39 Boy KartonBoy Karton 5753 gold badges9 silver badges13 bronze badges 1
  • A lot of browser block popups... – tur11ng Commented Mar 13, 2017 at 21:58
Add a ment  | 

3 Answers 3

Reset to default 2
javascript:popit(window.html);

Replace with:

javascript:popit('window.html');

Your click handler code is syntactically incorrect:

<a href="#" onclick="popit('window.html');">CLICK ME!</a>

Always, always have your developer console open to check for JavaScript errors! (edit — actually in this case there wouldn't have been an error; window.html would resolve to undefined probably! Still, keep the console open :-)

Also note that I used an "onclick" attribute instead of "href".

A GOOD working code with NO crashes.

Simple and what makes this code better is that you can use it in a JavaScript file separately and have it fairing to more then one file with the same popup size even though its different pages on popups.

Javascript

// Popup window code
function MyPopUp(url) {
    popupWindow = window.open(
        url,'popUpWindow','height=454,width=580,left=0,top=200,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}

HTML

<a href="JavaScript:MyPopUp('MyDirectory/Page.html');" title="My PopUp For You">My PopUp</a>

NOTE: You can also use this as onload in body for example <body onload="JavaScript:MyPopUp('MyDirectory/Page.html');"> and it will aslo work on onmouseover and others... though I do not advise this unless you want to piss off the clients visiting your page.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744838332a4596398.html

相关推荐

  • html - Popup window in Javascript - Stack Overflow

    In Javascript, I want to open my window.html file in a popup window. But it doesn't display any te

    2天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信