• 0

Simple javascript pop-up


Question

Any idea how to make an javascript popup? I already added the code from below but whenever I click the links it opens the same page (demo.html):

  Quote

<script type="text/javascript">

function popup(){

cuteLittleWindow = window.open("demo.htmlittleWindow", "location=no,width=614,height=222");

}</script>

<center>

<font face="Verdana"><font size="-1"><b><a href="http://www.mywebsite.com/"><font color="#000000">Home Page</font></a> | <a href="javascript:popup()">Demo</a> | <a href="javascript:popup()">Contact</a></b></font></font>

</center>

..and it looks like this:

DG6VE.png

What I'm doing wrong? Cause I know it's pretty simple but I'm not good a html. Thanks.

Link to comment
https://www.neowin.net/forum/topic/1120482-simple-javascript-pop-up/
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Well, it works for me in Chrome, Firefox and IE 10. Normally I would say when you use the "javascript:xxx()" form in an href, to terminate it with a semi-colon ("javascript:xxxxx();")... but rules aren't very strict anymore and that seems to work in recent browsers. Is the window opening behind your browser? Do you have popups disabled or some other security setting enabled?

  • 0

Yes, there are no errors and there's not any other Javascript code apart from that. It's a pretty simple page, nothing complex.

The window opens as it should in the front. Maybe I didn't explained well the problem. The script is working but what doesn't work is this:

1. I have 3 menus: HOME | DEMO | CONTACT (so 3 pages) INDEX.html - DEMO.html and CONTACT.html

2. The javascript resides on the INDEX.html

3. If I click on DEMO it opens the DEMO.html as it should in the front of my browser.

4. But if I click on CONTACT it opens the same DEMO.html and not CONTACT.html

  • 0

I'm not really sure what you're asking, but if you want your links to open a new window, the "name" parameter needs to be: name="_blank". The value "littleWindow" will always point to the same window with every click. "_blank" will spawn a new window/tab with every click.

  • 0
  On 18/11/2012 at 21:39, Copernic said:

Yes, there are no errors and there's not any other Javascript code apart from that. It's a pretty simple page, nothing complex.

The window opens as it should in the front. Maybe I didn't explained well the problem. The script is working but what doesn't work is this:

1. I have 3 menus: HOME | DEMO | CONTACT (so 3 pages) INDEX.html - DEMO.html and CONTACT.html

2. The javascript resides on the INDEX.html

3. If I click on DEMO it opens the DEMO.html as it should in the front of my browser.

4. But if I click on CONTACT it opens the same DEMO.html and not CONTACT.html

Ohhhhhhh! :) Yes, I very much misunderstood your question/problem. Use target="_blank", pass the page name as a parameter or use a separate javascript function, and also NAME the window dynamically in the open function.

  • 0

This was my little version to test yours...

  Quote

<script type="text/javascript">

var aPage = new Array();

var aHandle = new Array();

aPage[0] = "somepage.html";

aPage[1] = "someotherpage.html";

aHandle[0] = null;

aHandle[1] = null;

function popupbyidx(idx) {

var prefix = "winname_";

aHandle[idx] = window.open(aPage[idx], prefix + idx, "location=no,width=614,height=222");

}

function closebyidx(idx) {

aHandle[idx].close();

}

function popup(page){

cuteLittleWindow = window.open("demo.htmlittleWindow", "location=no,width=614,height=222");

}</script>

<center>

<font face="Verdana"><font size="-1"><b><a href="http://www.mywebsite.com/"><font color="#000000">Home Page</font></a> | <a href="javascript:popupbyidx(0);">Demo</a> | <a href="javascript:popupbyidx(1);">Contact</a></b></font></font>

</center>

<center>

<font face="Verdana"><font size="-1"><b><a href="http://www.mywebsite.com/"><font color="#000000">Home Page</font></a> | <a href="javascript:closebyidx(0)">Close Demo</a> | <a href="javascript:closebyidx(0)">Close Contact</a></b></font></font>

</center>

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Fan Control V230 by Razvan Serea Fan Control is a powerful and versatile portable utility that allows you to monitor, control and customize the fans of your GPU and CPU to keep your machine cool and running smoothly. Fan Control supports a wide range of devices and hardware configurations, giving you complete control over your computer's cooling system. Fan Control backend is mainly based on LibreHardwareMonitor, an open source fork of the original OpenHardwareMonitor. This means that hardware compatiblity is entirely open for anyone to contribute, and doesn't rely on a single developer who may stop caring at some point. Combined with the plugin system, Fan Control is unlocked for many generations of hardware to come. Main features Guided setup process on first launch Save, edit and load multiple profiles Change the theme and color of the application. Multiple temperature sources ( CPU, GPU, motherboard, hard drives... ) Multiple fan curve functions, including a custom graph Mix fan curves or sensor togethers (max, min, average) Low resource usage Advanced tuning with steps, start %, stop %, response time and hysteresis FanControl V230 changelog: Update LibreHardwareMonitorLib (ITE IT8696E lost controls) Update translations Download: FanControl V229 | Installer ~15.0 MB (Open Source) View: Fan Control Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • "Conflicts of interest", says the man that put Elon Musk, Mr. Conflict of Interest #1 Himself, in charge of a government agency supervising his own contracts.
    • With our Labor unions, a snowball's chance in hell has more probability.
    • inception horn at max volume every time you copy.
  • Recent Achievements

    • First Post
      EzraNougat earned a badge
      First Post
    • One Month Later
      westDvina earned a badge
      One Month Later
    • Community Regular
      Bern@rd went up a rank
      Community Regular
    • Week One Done
      Joey Solo earned a badge
      Week One Done
    • Week One Done
      Vicente C Alves earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      711
    2. 2
      +FloatingFatMan
      200
    3. 3
      ATLien_0
      163
    4. 4
      Xenon
      130
    5. 5
      wakjak
      110
  • Tell a friend

    Love Neowin? Tell a friend!