1

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?

1
  • A lot of browser block popups... Commented Mar 13, 2017 at 21:58

3 Answers 3

2
javascript:popit(window.html);

Replace with:

javascript:popit('window.html');
Sign up to request clarification or add additional context in comments.

Comments

0

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".

Comments

0

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.

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.