Jump to content

Recommended Posts

Posted

I was wondering if anyone knew how to change this script so it will load everytime the page it's loaded in is visited? It will only work once for me but I will need it to load everytime a person visits a certain page due to it's nature.

 

 

<script LANGUAGE="JavaScript">

<!--

function GetCookie(name) {

var arg=name+"=";

var alen=arg.length;

var clen=document.cookie.length;

var i=0;

while (i<clen) {

var j=i+alen;

if (document.cookie.substring(i,j)==arg)

return "here";

i=document.cookie.indexOf(" ",i)+1;

if (i==0) break;

}

return null;

}

var visit=GetCookie("COOKIE1");

if (visit==null){

var expire=new Date();

window.name = "thiswin";

newwin=open("newindex.html", "dispwin",

"width=450,height=455,scrollbars=yes,menubar=no");

expire=new Date(expire.getTime()+7776000000);

document.cookie="COOKIE1=here; expires="+expire;

}

// -->

</SCRIPT>

Posted (edited)

Are you using the onload method in the body tag?

 

It would look like <body onload="GetCookie()">

 

This would call the function every time the page loads.

 

There are lots of other ways of triggering events for example

 

onunload="GetCookie()" would run the script when the visitor leaves the page.

 

Is this the sort of thing your after?

 

Edit: hang on, do you mean you want the new window to open regardless of whether or not the cookie is set?

Edited by Digirunt
Posted

Well, Im gonna put this script in the body of my index.html page. I tried to do it on my local browser and it worked the first time but it would'nt work again, meaning it did'nt pop-up again. So I assume that it's set not to work more than once.

Posted

Its creating a cookie on the clients machine, then when they return it checks if it's there and if it is returns false or doen't do anything.

 

What do you want to happen?

 

This script may not be the right one for you.

 

I have hundreds of pre written script so tell me exactly what your after!

 

:)

Posted

A simple solution is

 

><script LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!-- Hide script from old browsers

function newWindow(url){
 popme = window.open(url, "name", "width=400,height=500, scrollbars=yes" )
 popme.focus()
}

// End hiding script from old browsers -->
</SCRIPT>

 

Add the above to your head section then call it on loadup with:

 

><body onload="newWindow('yourpage.html')">

 

insert the onload="newWindow('yourpage.html')" into your pages body tag and change youpage.html to the url of the page you want to appear in the popup.

 

I like this one because you can have alink open a different page in the popup without extra code.

eg

><a href="javascript:newWindow('anotherpage.html')">Link</a>

 

Explanation:

 

the script is opening a new window but will not do it until it is called to action.

 

The newWindow() is calling the script.

 

The newWindow('yourpage.html') is specifying the url of the page to display in the pop up.

 

The "width=400,height=500, scrollbars=yes" can be editted to change the appearance of the window.

 

The popme.focus() is simlpy making sure the window is infront of the current browser window when it loads.

 

 

Is this what your after?

Posted

OK I'm off to bed now as it's 2am and I can no longer think straight.

 

If you have any difficulties post here and I'll take a look tomorrow.

 

Good luck.

 

Thumbs Up

Posted

Hi,

 

Can I really ask why you need a popup? Pop ups on pages are the most annoying thing in the world, espically if I am surfing a site, the last thing I want to see is a popup telling me I am the 1 millionth winner or that my computer is unsercure!

 

Just a little pointer thats all!

 

Jim

Posted

Yes thats a very valid point Jimuni,

 

Popups can be annoying and are rarely put to good use.

 

People often disable them so do not use them for important functionality or you will be closing your site off from some of your visitors.

 

Using links that open in new windows goes against the rules of good accessibilty.

You should at least use;

 

"view stats in a new window" as a link to a popup or new window instead of just

 

"view stats" or worse still "Click here".

 

I'm not trying to impose my opinions on you though hence why I just answered the question first.

 

Thumbs Up

Posted

Yay it works.

 

I have looked at your html code while I was visiting your site and discovered a few areas that you could benefit from help with in future.

 

I have written a detailed exlpanation of what problems I found and how to remedy them.

 

Hope this helps

 

I am not saying you should redo all your sites pages but I am hoping it will help you in future projects you undertake as you are obviously a very keen web designer as i can see a lot of hard work has gone into your site.

 

Thanks again

 

Digirunt

Thumbs Up

Posted

I'm going to read it and get back to you. I was in a big rush to get the site up before the album dropped and I never went back and corrected a few things I knew that I should have. When I first say my site listed in Google I noticed a major error in the site description that was good and bad. Anyway, I'll check it out.

  • 2 weeks later...
Posted

I made a few changes Digirunt and will continue to work on it.

I used the notepad program to build my site. I taught myself this stuff so that's why a lot of it is incorrect. Thanks for your help. Please feel free to remove that page, I saved your work.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...