Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HELP with modal window

    Hi guys,

    i have this in a page:

    Code:
    function show_habit() {
      self.name = "Parent_Window"; 
      if (document.all)
        window.showModalDialog("programas/habitacoes.php","","dialogWidth:780px;dialogHeight:500px")
      else {
        alert("You need IE")
      }
    }
    <a onClick="show_habit()">Test</a>
    And in the modal window

    Code:
    <base target="Parent_Window">
    
    function set_link(id) {
      switch (id) {
        case "1":
          a = "http://www.google.com";
          break;
      }
      return a;
    }
    <a href="" onclick="return set_link('1')">google</a>
    But it dont work and no error occurs. The modal page opens but inside it when i click "google" it goes to the folder where the html page is instead of http://www.google.com.
    Can anyone help me in this one?? Thanks
    Last edited by mcoelho123; 08-04-2006 at 04:42 PM.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,470
    Thanks
    0
    Thanked 634 Times in 624 Posts
    That code will crash Opera.

    document.all does not identify support for window.showModalDialog

    document.all identifies that the browser is IE or Opera (or some other more obscure browser that also happens to recognise it.

    To test for window.showModalDialog support test like this:

    if (window.showModalDialog)
    window.showModalDialog("programas/habitacoes.php","","dialogWidth:780px;dialogHeight:500px")
    else {
    alert("I am using intranet only code on the internet so it doesn't work in your browser")
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    i think that this will maybe work, when i tested it the link it displayed the localsite in the IE status but upon clicking the link you are directed to google.

    Code:
    <base target="Parent_Window">
    <script language="javascript">
    
    function set_link(id, linkID) 
    {
    
      switch (id) 
      {
    
          case "1":
    
               a = "http://www.google.com";
    	  
               break;
    
      }
      
      document.getElementById(linkID).href = a;
    
    }
    </script>
    <body>
    	<a id='linkID1' onClick="set_link('1', 'linkID1')" href='' target="_blank">Google</a>
    </body>
    I hope this works for you.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Code:
    function set_link(link, id) {
      var a;
      switch (id) {
        case "1":
          a = "http://www.google.com";
          break;
        //...
      }
      link.href =  a;
      return true;
    }
    ...
    <a href="#" onclick="return set_link(this, '1')">google</a>
    But why not just hardcode the href of each link if the function will simply change the href and nothing more?


  •  

    Posting Permissions

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