SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Java Script Function

    Hi

    I have a Javascript function showMap() that shows some map. Like the function has window.open() and that opens a specific page to show specific map.

    Now I have a list of Address. What i want is to hae a function that will do the following :

    function showMap(page-to-display)
    {
    window.open(page-to-display);
    }

    Now, i have an image "Show Map" for all the address. What i want is to make that image ClickAble, and on the Click event i will use showMap(page). for example:

    Images
    ------
    Atlanta On the click event showMap("atlanta.html")
    Ohio On the click event showMap("ohio.html")
    Utah On the click event showMap("utah.html")
    Texas On the click event showMap("texas.html")

    the showMap function, will open the respective files in popup.
    Plz Guide

  2. #2
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    Denver
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Zeeshan, Not sure what exactly you're asking, but if you just want to make an image clickable, all you have to do is wrap it with <a></a> tags. something similar to this.
    <a href="#" onclick="javascript:showmap();"><img src="image.gif" /></a>
    Let me know if this helps.

  3. #3
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok this will help but here is what i want.
    <a href="#" onclick="javascript:showmap();"><img src="image.gif" /></a>

    this is what u provide, now that i want is to pass the URL of the HTML page to be loaded here with the showmap() like showmap(atlanta.html) means

    <a href="#" onclick="javascript:showmap(atlanta.html);"><img src="image.gif" /></a>

    now this atlanta.html should be further passed to window.open() whcih in inside the showmap() function. like

    function showmap(function-parameter)
    {
    window.open(function-peremeter)
    }

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript">
    function showmap(page){
    window.open(page,'Map');
    }
    </script>
    
    <a href="#" onclick="javascript:showmap('atlanta.html');"><img src="image.gif" /></a>
    Saul

  5. #5
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot.

  6. #6
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're welcome.
    Saul

  7. #7
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but this opens another page like

    index.html#

    instead of my POPUP

  8. #8
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What's your definition of popup? Perhaps you wanna make the window without toolbar, scrollbar and specified width?

    In that case, you need to specify extra parameters:
    Code:
    window.open(page,'Map','toolbar=0,status=0,menubar=0,fullscreen=no,width=400,height=400,resizable=0,scrollbars=1');
    Saul

  9. #9
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No no I do not mean that . I know the POPUP thing. But the problem is that if i have the FOLLOWING CODE in index.html

    <a href="#" onclick="javascript:showmap('atlanta.html');"><img src="image.gif" /></a>

    then the browser opens another INDEX.HTML page and the address bar shows INDEX.HTML#

    this is what the problem is.

  10. #10
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Please let me know what is worng with this code.

    <a href="javascript:viod(0)" onClick="showmap('zeeshan.html');"><img src="showmap.gif"></a>



    <script language="javascript" type="text/javascript">

    function showmap(page)
    {
    var w = screen.width, h = screen.height;
    if (document.all || document.layers)
    {
    w = screen.availWidth;
    h = screen.availHeight;
    }
    var popW = 500, popH = 330;

    var leftPos = (w-popW)/2, topPos = (h-popH)/2;

    window.open(page,'Googel Map','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);
    // if (window.focus) {newwindow.focus()}
    return false;

    }
    </script>

    -----------------------
    this shows a page in the borwser with Address bar location = javascript:viod(0)

  11. #11
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You have a type in javascript:viod(0), should be void. And you cannot have a space in window title text in IE. 'Google Map' will not work in IE.

    Other than that it's OK. I've tested it and it opens a popup like it supposed to.
    Saul

  12. #12
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok this is working , it opens the PoPUP, but strange, it opens anotehr browser windows where it opens javascript:void(0) in the address / URL

  13. #13
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What browser do you use? I don't have this problem when testing your code on IE and FF.
    Saul

  14. #14
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i m using IE and FF. FF showing a Blank page (with blank address) while IE shows blank paeg with "javascript:void(0)" in address bar

  15. #15
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    OK, then if you don't need <a> tag for SEO, just remove it and set onclick to the image, to make it look clickable you can use CSS:
    Code:
    <img src="showmap.gif" onClick="showmap('zeeshan.html');" style="cursor:pointer" />
    Saul

  16. #16
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats great , Thanks

  17. #17
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're welcome
    Saul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •