...

View Full Version : Please Help with Java Script Code That Triggers Open In New Browser/Window



roco
01-10-2012, 05:35 AM
Hello all,I have a website and I would like a pop-up window to promote a new website venture I have. I would like for the new website to open in a completely new window/browser when my members simply click on the index page (No link or Buttons).The code below does most of what I ask lol,but it..

1.Only opens in a new tab (in same browser) while I would like for it to open in a completely new browser "full page" menu bar scroll tab and all.
plus
2.It seems to open each and every time the page is clicked,which will be annoying to my members.I would only like for it to open 1 time per visitor every 24 hours or whenever cookies are cleared.


<html>

<head>
<script type="text/javascript">
function click_on()
{
window.open("URL HERE", "_blank");
}
</script>
</head>

<body onclick="click_on()">

</body>

</html>

I am no expert at this,and my knowledge is very limited,so excuse me if this is a simple situation.Any help would be greatly appreciated.

Thanks,
Roco

Philip M
01-10-2012, 08:08 AM
"_blank" causes the page to open in a new window.

To allow the page to be opened only once per 24 hours:-


<html>
<head>
<title>Cookie: permit page to show once a day</title>

<script type="text/javascript">
var show = false;
function click_on() {
if (show) { // only if the cookie was not found
window.open("http://www.google.com", "_blank");
}
}
</script>

<script type="text/javascript">

function checkBanner() {
show = false;
if ( document.cookie.indexOf("zy181gg$xx") < 0 ) { // cookie not found
show = true;
click_on(); // for testing
// if cookie not found set it
var expDate = new Date();
expDate.setTime(expDate.getTime()+24*60*60*1000); // one day ahead
document.cookie = "gyz$xx=zy181gg$xx; expires=" + expDate.toGMTString() + "path=/";
}
}

</script>

</head>

<body onload = "checkBanner()">
<div id = "container" onclick = "alert('User Clicked'); click_on()">
THE WEBPAGE IN HERE
</div>


</body>
</html>


"In the beginner's mind there are many possibilities, but in the expert's mind there are few” - Shunryu Suzuki (Japanese Zen priest, ?-1971)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum