SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: Linking

  1. #1
    Wishful Thinking webmasternovis's Avatar
    Join Date
    Jul 2002
    Location
    England
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Linking

    Hi all,

    I have never used Javascript before, so please exuse if this is totally wrong[img]images/smilies/smile.gif[/img]

    Anyways, I am trying to link to a page, which will hide it'a address bar, back buttons etc...

    I have the following code:
    Code:
    <a href="java script:void" window.open('http://www.example.com','Window Name','toolbar=no','location=no','directories=no','menubar=no')><img border='1' src="http://picture.jpg"></a>
    But all I get is a "Error on Page" message at the bottom of the screen.

    Anybody know whats up?

    Thanks a lot,
    Mike[img]images/smilies/smile.gif[/img]

  2. #2
    011521 dbalsdon's Avatar
    Join Date
    Feb 2003
    Location
    North Of Scotland
    Posts
    444
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this should work

    <a href="java script:void" onClick="window.open('http://www.example.com' , 'Window_Name' , config='toolbar=no,location=no,directories=no,menubar=no'); return true"><img border='1' src="image-destination" /></a>

    New Window should be New_Window.. you cant include spaces...

    you also need to include config= to the window.open coding..

    edit:
    remember.. if you do copy and paste this code.. be sure to remove the space between java script...and change the image src url..
    Daniel Balsdon
    My Site

  3. #3
    Wishful Thinking webmasternovis's Avatar
    Join Date
    Jul 2002
    Location
    England
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks mate

  4. #4
    Wishful Thinking webmasternovis's Avatar
    Join Date
    Jul 2002
    Location
    England
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi again,

    Just tested it out and it 'half works'

    Everything works, but the problem is that I still get the Error on Page message at the bottom of the screen.

    Anyone know whats wrong?

    Thanks a lot,
    Mike

  5. #5
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dbalsdon
    you also need to include config= to the window.open coding.
    I've been using error/problem-free popups for years and that's the first I've ever heard of using 'config='.

    ---

    webmasternovis, do you have a url where we can see exactly how you've used it as well as seeing the surrounding (code) context?
    (I've not been able to replicate the error myself.)
    New Plastic Arts: Visual Communication | DesignateOnline

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

  6. #6
    Wishful Thinking webmasternovis's Avatar
    Join Date
    Jul 2002
    Location
    England
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Bill,

    The actual error appears here and the surrounding code is PHP code - which I know is not the problem, as I have tested it without the PHP.

    Anyway, here is the surrounding code:

    PHP Code:
     if ($number)
      {
       echo ?><a href="javascript:void" onClick="window.open('http://www.template-help.com/aff/preview_neutral.php?aff=templatestorm&i=1971&skin=21&pr=yes&src=""yes&nt=yes&level=0','Template_Preview',config='toolbar=no,location=no,directories=no,menubar=no');return true">
                      <img border='1' src="http://65.61.153.134/screenshots/1900/1971-m.jpg"><br><br><?";
       echo "
    ?><a href="javascript:void" onClick="window.open('http://www.template-help.com/aff/preview_neutral.php?aff=templatestorm&i=2090&skin=21&pr=yes&src=""yes&nt=yes&level=0','Template_Preview',config='toolbar=no,location=no,directories=no,menubar=no');return true">
                                       <img border='1' src="http://65.61.153.134/screenshots/2000/2090-m.jpg"></a>
    <?
      
    }
    ?>
    Thanks a lot,
    Mike

  7. #7
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firstly, it appears that you aren't closing the first <a> tag.
    I would guess that this is creating the problem as the browser is attempting to start the second link definition before it has been told where first link defination ends causing a problematic overlap in the structure of the javascript instructions ('syntax error').

    ---

    Fwiw,...

    Try adding the destination url to the href attribute instead (replacing the javascript: void).

    Replace the return true with return false

    This should provide an error-free, 'belts and braces' link that will create a popup if javascript it enabled, but will simply forward the existing browser window to the destination url if javascript isn't enabled.

    Also, it would be better for your markup if you were to wrap the guts of the popup code into a header/externalised function.
    The destination url could remain as a variable which means you'd only need to call the function and mention the url, rather than repeat the entire window.open() procedure again.

    e.g.

    in the head of your current page (or in an 'external js file' linked to in the header of your current page*):
    Code:
    function popUp(url) {
    window.open(url,'Template_Preview','toolbar=no,location=no,directories=no,menubar=no');
    }
    (* Note: If 'embedding' the javascript function in the head of a page you will need to use <script type="text/javascript"> ... </script> around the function.)


    In the body:
    Code:
    <a href="destination.html" onclick="window.open(this.href,'Template_Preview','toolbar=no,location=no,directories=no,menubar=no');return false">link element</a>
    I hope that helps.
    New Plastic Arts: Visual Communication | DesignateOnline

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

  8. #8
    Wishful Thinking webmasternovis's Avatar
    Join Date
    Jul 2002
    Location
    England
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Bill

    Thanks very much for all your help - I understand everything apart from a couple of points.

    Firstly, do the two bits of code you posted work together so to speak? Like do I use them on the same page, or were they two different options?

    Also on the second bit of code you have this.href. Would you mind telling me what that means and if I just keep it there?

    Thanks again,
    Mike

  9. #9
    SitePoint Wizard Bill Posters's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. The two bits of code should be used together.
    The first part (head/external) simply predefines what the function should do when it's called.
    The second part (body) shows how the link tag <a> should be structured so as to call the prescribed function and also how to tell the function which url (variable) to use in the popup window.

    2. this.href is kinda like javascript shorthand for saying that 'the href that is also present in this <a> tag.

    You could alternatively rewrite the entire destination url in place of this.href and it would work exactly the same.
    I choose to use this.href i these cases as it saves on repeating code.

    By using the destination url in the href value and referring back to it in the javascript function with this.href, you only need to change the (long) url in one place rather than two, when making changes.

    Hope that hasn't confused you further
    New Plastic Arts: Visual Communication | DesignateOnline

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

  10. #10
    Wishful Thinking webmasternovis's Avatar
    Join Date
    Jul 2002
    Location
    England
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It all works now, thanks for all your help mate!

    Mike

  11. #11
    Wishful Thinking webmasternovis's Avatar
    Join Date
    Jul 2002
    Location
    England
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Argh!

    All was working fine, but I have come across another problem

    I am sure that all the code is consistant, but somehow some links open as a popup without an error, and others do the total opposite.

    Please could someone have a look?

    www.templatestorm.com/test/featured.php (you may refresh as it uses the random feature of php, and its not all finished yet!)

    Thanks very much,
    Mike


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
  •