Jump to content
xisto Community
soleimanian

How To Create A Popup Window With Javascript?

Recommended Posts

Please help me!I want to in popup massage suggest to visitors of my site to make my site their home page .Please note that I have some script code that visitors most click on a text to make my site their home page .Every one that can help me please send an email to soleimanian@noavar.com

Share this post


Link to post
Share on other sites

as wappi suggested you can use the onload="" in the BODY tag and then call the function from the javascript file to load, something like this:

<body onload="popup()">

The above code calls the function from the Javascript file or if you have it embedded in the webpages. The below code is what you need to open the page in the popup, this can be pasted into an external file which contains all the javascript or embedded as i said previously.

function popup() {	window.open("popuppage.html","Homepage","resizable=no,status=yes,scrollbars=yes,width=260,height=500");}

If you require any help or do not understand then ask :).

Share this post


Link to post
Share on other sites

i have to agree but some people have to learn these things by trial and error. People have to try new things and then get feed back on what is good or what might drive people away from their site. And having a pop-up which instantly loads the moment the page is opened is not a good idea, only for the reason that everyone will instantly close it, whether it contained important information or not. It is best to just have a text link saying 'make this your homepage'.

Share this post


Link to post
Share on other sites

I'll have to agree with dissipate and overture. It does not make a site very attractive to the user if you do that. Why? its annoying and most other websites that are ... not so good sites like they promote spyware and adware use those kinds of schemes.I would rahter just make a link that says "add this page to your favorites list!" or something like that.

Share this post


Link to post
Share on other sites

I think he wants to know the code to pop up the yes/no dialog box asking the user if he would like to set his page as there start/home page.I will dig for the js code to do it.

Share this post


Link to post
Share on other sites

<body STYLE="behavior:url('#default#homePage')" ID=sID onLoad="sID.setHomePage('http://www.yoursitehere.com/')">

Will pop up dialog box asking if you would like to set http://www.yoursitehere.com/ as your homepage.

There is no standard so there are very few browsers it will work in.
I don't think NS has ever had support.
IE5 supported it but I am not sure if the syntax was the same.

Share this post


Link to post
Share on other sites

Here is code to make a link to add current page to favorites: <a href="java script:" onClick="window.external.AddFavorite(location.href, document.title);">add to favorites</a>

Share this post


Link to post
Share on other sites

I know of another simple way to make a window pop-up so you can suggest to your visitors to make your site their homepage.

 

function popUp() {  alert("Please make my site your homepage!");}

You just put the code above together with your other script code in the <script> tag -- that is within the <head> tag. How it works is that the "alert" function will pop up as an alert box and whatever message you want your site visitors to see first when they get to your site will be displayed in small pop-up window (AKA the alert box). In between the quotations within the parenthesis is what will appear in the alert box. I just put "Please make my site your homepage!" as an example but you can change that part of the message to whatever you want it to be.

 

And now, in the body tag, have the following:

 

<body onload="popUp()">

This code is as oveture explains. It will call the function called (well, in this case) "popUp()" and "onload" (which means that when your webpage loads), the function being called will be executed. So... if you don't have the "onload" function in the <body> tag, the script from how to pop-up a window will not work.

 

Okay, I hope that helps you out. A really simply code and I believe it fits what you are asking for. ^__^

 

Regards,

-- scryoko

Share this post


Link to post
Share on other sites

It depends on what type of prompt/alert you want.

For example, if you want to have a pop-up on a page when someone enters it, use this code:

<script language="JavaScript type="text/javascript"">alert("Place your message here!")</SCRIPT>

Or you can get one that pops up when someone leaves the page:
<body onunload="alert('Place your message here!');">

Also, there is one when a visitor moves their pointer over a link:
<a href=""onMouseover="alert('Place your message here!')">Put the text you want to be visible here.</a>

B)

Or if you want something more cool, make one that says the time and date upon entering a page:
<script language="JavaScript" type="text/javascript">document.write("Having a great day?")document.write("<BR>")document.write("Today's date is ",Date())</script>

Finally, you could use one that comes up when you enter and leave a page.
<body onload="alert('Place your message here!');"onunload="alert('Place your second message here!');">

Share this post


Link to post
Share on other sites

Can't you make a question window with Javascript? I'm not an expert on Javascript (I actually don't know anything about it), but I know it can be done in VB, problem is, can it be done in Javascript? Something like this:

if(!isAdded) { // use a var from a cookie to check wether your site is already added to favorites  if(question("Do you want to make my site your homepage") { // Ask to add this site	window.external.AddFavorite(location.href, document.title);  }}

I'm almost sure this isn't correct javascript and I don't know how to use cookies, so plz rewrite this code, but isn't this a nice idea instead of the popup?

-=jeroen=-

Share this post


Link to post
Share on other sites

Grrr. You're the type of person we all don't like. j/k.NEVER EVER EVER EVER HAVE POP-UPS ON YOUR SITE TO ASK PEOPLE TO DO SOMETHING.If they want to make your site part of their favourites, then they will do. If they want to make it their home page, then they will do. If they don't have the technical knowledge, then use simple inline javascript as well as a link to achieve the effect.It is possible to create in document pop-ups, using AJAX, but I aint telling you how, as I do not know myself.

Share this post


Link to post
Share on other sites

I have a further question. How can I actually create multiple pop-ups that trigger by a mouse click over a particular area in a picture! I WILL ACCEPT ANY SUGGESTIONS OR SCRIPT THAT MAY HELP and give me an idea or two!!! THanks-Badi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.