Javascript: Popup window
Suppose you want to redirect a user to another page, but you don't want the user to leave your site. To accomplish this, you will need to use popup script that generate a new window, thus, keep your website window intact. First you need to create javascript function and place it between the scripts tags in the html page. Here is the code for the part:
You can specify the height and the width of the browser by setting it in the function popitup(url).
| HelloWorld.html |
|
function popitup(url)
{
newwindow=window.open(url,'name','height=800,width=700,scrollbars=1');
if (window.focus) {newwindow.focus()}
return false;
}
var newwindow;
function poptastic(url)
{
newwindow=window.open(url,'name','height=400,width=400');
if (window.focus) {newwindow.focus()}
}
|
Now let’s say that you want to redirect a user to google search page, here is the code that will accomplish this task:
The url parameter is the yahoo page that you are passing to the function.
|
<html>
<body>
<a href=’http://www.google.com’ onclick="return popitup(http://www.google.com')">
</body>
</html>
|
Click here to see a preview of the pop up window
|
|
|