SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with piece of code

    The following works for me in explorer but will not work for me in netscape navigator. Can anyone suggest a way of doing it so it will work on both browsers.
    Here is the piece of code I am having problems with.
    <img src="button.gif" onClick="window.location='some-url' ">

  2. #2
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While there shouldn't be a space between the ' and the ", I can see no fatal flaw in the code.
    I tried it with the space in Camino and NN7 and it worked fine in both cases.

    I trust 'some-url' is just a placeholder for this posting only, right?

    Try nesting the <img> in some <a> tags instead as you would do with a normal link.
    Is there a reason that you are using this particular method to produce a link effect?
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Bill Posters
    While there shouldn't be a space between the ' and the ", I can see no fatal flaw in the code.
    I tried it with the space in Camino and NN7 and it worked fine in both cases.

    I trust 'some-url' is just a placeholder for this posting only, right?

    Try nesting the <img> in some <a> tags instead as you would do with a normal link.
    Is there a reason that you are using this particular method to produce a link effect?
    Some-url is ticket.php?loc=<?php echo"$venue" ?> . Could it be that I am linking to a php page be the reason it will not work on netscape?

  4. #4
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whilst I no absolutely nothing about PHP try this replacing the two double-quotes (") within the <? ?> to apostrophes.

    It could just be that the first double-quote in the <??> is prematurely closing the javascript command.

    Code:
    <img src="button.gif" onClick="window.location='ticket.php?loc=<?php echo'$venue' ?>' ">
    I can't say for sure that this is what is causing the problem, but improperly nested quotes/double-quotes can be fatal to a script.


    Again, why not declare it as an href in an <a> tag instead of pushing it onto a javascript event within the <img> tag?
    New Plastic Arts: Visual Communication | DesignateOnline

    Mate went to NY and all he got me was this lousy signature

  5. #5
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol, no need to get into PHP, just do this:

    <Script language="JavaScript">
    function goTo(the_doc) {
    window.location.href = "http://www.yoursite.com/"+the_doc+".html";
    }
    </script>


    <img src="button.gif" onClick="goTo('someURL')">

    Just use the goTo() function to send visitors to web pages...and whenever you call it, pass the web page name of the page you want to send them to. So this button image would send the visitor to someURL.html when clicked.

  6. #6
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    gregc's solution will do it, but not because it's a function - it's because setting "window.location" equal to a new URL is sloppy/invalid code (although IE tolerates it, NS doesn't), and gregc's code correctly uses "window.location.href", which is the correct way to do it.
    Last edited by M@rco; Mar 15, 2003 at 18:35.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  7. #7
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    As said by Bill Posters.. why not use anchor tags to achieve this?
    Code:
    <a href="ticket.php?loc=<?=$venue?>"><img src="button.gif" alt='button' /></a>

  8. #8
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Thanks........

    I used top.location=
    pretty bad then.....already changed it to window.location.href
    I was just told that my site cannot be seen on a Mac, although with IE broswer. Could it be this thats causing the Mac problems?
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  9. #9
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Said twice already, but still no response.....
    WHY NOT USE ANCHOR TAGS?
    Why are you trying to replicate basic HTML features with JavaScript?
    Do you not want the links to be crawled?

    Last edited by M@rco; Mar 16, 2003 at 10:26.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  10. #10
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    pages built in js

    Quote Originally Posted by M@rco
    Said twice already, but still no response.....
    WHY NOT USE ANCHOR TAGS?
    Why are you trying to replicate basic HTML features with JavaScript?
    Do you not want the links to be crawled?

    You must know by now that it has become popular to use JS for common features, including menu building. I am getting near 40 pages, I really don't like the idea of writting the same content 40 times. So I do alot in JS, and provide HTML links and sitemaps where needed.

    My site still fits on a floppy disc!!! leaves loads of space of my 10Mb for samples, rhythm arrays, pics etc.

    So long as you include alternative methods of navigation, this method seems completely fine..........
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  11. #11
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Markdidj
    You must know by now that it has become popular to use JS for common features, including menu building. I am getting near 40 pages, I really don't like the idea of writting the same content 40 times. So I do alot in JS, and provide HTML links and sitemaps where needed.

    My site still fits on a floppy disc!!! leaves loads of space of my 10Mb for samples, rhythm arrays, pics etc.

    So long as you include alternative methods of navigation, this method seems completely fine..........
    I'm not saying that JavaScript shouldn't be used at all, I'm saying that in this particular case (i.e. using JavaScript onClick events to replace a standard hyperlink) it's pretty pointless.

    The only advantage that I can see is that the links won't be crawled by search engines, but that's only an advantage if that's actually what you want!!

    The (other) disadvantages include reduced compatibility with other devices and/or platforms (e.g. PDAs, mobile phones), less convenient to format with CSS, lack of support for tooltips with the TITLE attribute, more difficulty in parsing (e.g. when screenscraping), harder to edit content in Content Management Systems, longer page source code, etc. etc.

    I am genuinely intrigued to know what advantage it gives you over a standard <A> element, so please enlighten me!
    Last edited by M@rco; Mar 16, 2003 at 14:57.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


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
  •