56 users online (0 members and 56 guests)  


  Results 1 to 11 of 11

Related

  1. Please Help in a JavaScript Problem    Forum: Javascript Forum
    Replies: 2
  2. javascript link problem    Forum: Javascript Forum
    Replies: 4
  3. Simple Javascript Problem - I think...    Forum: Javascript Forum
    Replies: 3
  4. Javascript active link problem    Forum: Javascript Forum
    Replies: 0
  5. problem with javascript opening a new window    Forum: Javascript Forum
    Replies: 4
  1. #1
    hardwarecraz's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2002
    Posts
    5

    Help me with a Javascript problem!

    I am trying to define a fucntion with three parameters, URL, height and width so that I can open windows, with different HTML pages, with different sizes. I did the following:
    ==================
    <SCRIPT LANGUAGE="javascript">
    function openwin(htmlpage,mwidth,mheight)
    {
    window.open(htmlpage,'mywin', mwidth, mheight,'toolbar=no,menubar=no')
    }
    </SCRIPT>
    Above defines the function with three variables.
    Then at some appropriate point, I assign the variables as follows:

    <SCRIPT LANGUAGE="javascript">
    {var htmlpage="mypage.htm";
    var mwidth=1024;
    var mheight=700;
    }
    </SCRIPT>

    Then I call the function:
    <A HREF="javascriptpenwin(htmlpage,mwidth,mheight)">
    Click here to open the window
    </a>

    But the opened window size is not of the values in the variables! Help please! I am losing my mind and sleep!
    Thanks!

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hi there.

    Two things to remember, the a href tag is just HTML, its not clever enough to figure out that you are usign variables. So first off, call your function like this -

    Code:
    <A HREF="javascript: openwin('mypage.htm','1024','700')">
    Click here to open the window
    </a>
    Secondly, the format of your window opening code is incorrect. Variables have to be set in a certain way, and concatenated together if you are mixing variables and strings. I would try this -

    Code:
     window.open(htmlpage,'mywin', 'width=' + mwidth +', height=' +  mheight + ',toolbar=no,menubar=no')
    I checked, and this code works for me. Let us know how you get on.

    by the way, welcome to the forums!
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    hardwarecraz's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2002
    Posts
    5
    As you had pointed out, my format for window opening was indeed wrong - all I had to do was copy your tip into the page, and bingo! Everything works! Many many thanks! Glad I gave the bread to the baker!

  4. #4
    hardwarecraz's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2002
    Posts
    5
    I have one more question to the Guru - if in the above function, I call an image as the file name (like xyz.jpg), the resulting window contains the image with an offset in both x and y directions, in the top left corber of the window. If on the other hand, I put the image in a html page and call that html page, the image appears flush with the top left corner of the window. But I hate to create multiple html pages containing tens of images. How can I call the image window and not have an offset at the top left corner? Many thanks in advance.

  5. #5
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hmm. I do not get an offset, but then again, I use Mozilla, so maybe thats it.

    The problem with calling direct to an image is that the control is then completely out of your control, and into the browsers.

    Instead of hardcoding lots and lots of pages, how about using a server side script to achieve it?

    For example, PHP would handle it like this -

    Save a file called image.php with this code in -

    PHP Code:
    <img src="<? echo $_GET['image']; ?>.jpg">
    Then use a url like this to call the page -

    Code:
    href="javascript:openwin('image.php?image=Picture', '800', 600')"
    You would end up with a html page that contained the picture ( 'Picture.jpg').

    The only thing to watch would be not using the entire filename in the variable, as a user can change the url and end up accessing the servers file system if you are not careful.

    This relies on your server having php, so have a look and see if it works (dontr forget to call the file .php !)
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  6. #6
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    QuietDean:

    Can't find the thread from yesterday where you gave the URL to the Mozilla download so will ask here.

    I downloaded and installed it but it's not recognizing any of my JavaScript code. Couldn't find an option to fix that. Can you provide the 'super secret' instructions to enable JavaScript in Mozilla 1.1?

  7. #7
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Sure, its -

    Edit/Preferences/Advanced/Scripts & WIndows

    Set it to enalbe JavaScript for Navigator, then choose from the box below what you would like to work and whatnot.

    Be aware, a lot of JavaScript is , again, only for IE . Once again Microsoft promised to support a standard, then changed the standard so as to force it out of the hands of the average user.

    If in doubt, try a very simple test script and see if it works.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  8. #8
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Have 'all' the boxes checked at

    Edit/Preferences/Advanced/Scripts&Plugins

    but neither inline nor .js file referenced SCRIPTs are being read. Guess my web sites are going to make sense only to IE users until I figure out an alternative to the .js referenced files.

  9. #9
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Yours is different to mine, I got the latest 'stable' release, Mozilla 1.0 .

    Maybe you got the beta release? It may be a bug that JavaScript is not working, as JavaScript includes work fine for me. The only thing that never seems to affect my browser is things like 'no right click' and stuff like that.

    Check out your version, compare, maybe download the stable release if your is different to mine.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  10. #10
    benzden's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Feb 2002
    Location
    San Antonio, Texas
    Posts
    652
    Thanks, will go back and get the 1.0 version and see. What I did download was supposed to be the stable version prior to the 1.2 beta now being tested.

    Just installed version 1.0.1 and have same problem. Couldn't see where I could get just version 1.0. Also tried to access this forum to edit this messageand couldn't without logging in "under an unsecure" process according to the pop-up - mostly likely due to the new browser being used. Are there other Mozilla initialization steps I'm missing?

    (This version has a readme.txt file - it not having anything in it but installation instructions. The prior download referenced that file but didn't include it.)
    Last edited by benzden; 11-02-2002 at 10:52 AM.

  11. #11
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    hmm. I just installed and ran
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread