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 to the CF scene
    Join Date
    May 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "javascript:" links, submitting forms, and "open in new window"

    Disclaimer: I would love to refactor things so that we were not using "javascript:" links but that's what we inherited and we may not have time to (yet, at least).

    Anyway - from the FAQ:
    http://codingforums.com/showthread.p...428#post255428
    Q: How do I use 'javascript:' links?
    A: Consensus on this area among professional web designers is that they shouldn't be used at all. There are strong arguments arguments towards this, from usability, accessibility, optimisation and standards comformance perspectives. Before I tell you how to use them, please read through this list first...

    * Usability:
    Something not often mentioned but one of the most important
    factors in my view, is that the 'javascript:' pseudo-URI destroys
    several layers of usability features. E.g:
    - The link does in most cases only work when simply clicked, it
    generally no longer works:
    * When bookmarked
    * When users chose 'open in new window' or 'open in new tab'
    So - is this pretty much a fact of life with javascript: links?

    We have a page that looks something like this (example simplified for ease of understanding):

    Code:
    <html><body>
    
    <form id="recordDetailForm" action="details.jsp" id="theDetailForm">
        <input type="hidden" name="detailNumber" />
    </form>
    
    <script language="javascript">
        function goToDetail(_detailNumber) {
            var theForm = document.getElementById('theDetailForm');
            theForm.detailNumber.value = _detailNumber;
            theForm.submit();
        }
    </script>
    
    <a href="javascript:goToDetail('35');">open record 35</a>
    </body></html>
    This works fine if someone clicks the link normally, but if they right click the link and select "open in new window" they get "the page cannot be displayed" in IE. Firefox doesn't even offer "open in new tab".

    You may be thinking, "hey, why don't you just generate the URL detail.jsp?detailNumber=35"? The unfortunate/annoying thing is that the URL's are generated by the software we're using and we are still trying to figure out how to generate the right URL without using a form. (It's a long, sad story - just trust me, we wouldn't do it this way voluntarily)

    I saw an example that said to try this:


    Code:
    <html><body>
    
    <form id="recordDetailForm" action="details.jsp" id="theDetailForm">
        <input type="hidden" name="detailNumber" />
    </form>
    
    <script language="javascript">
        function goToDetail(_detailNumber) {
            var theForm = document.getElementById('theDetailForm');
            theForm.detailNumber.value = _detailNumber;
            theForm.submit();
            return false;
        }
    </script>
    
    <a href="#" onclick="goToDetail('35');">open record 35</a>
    </body></html>
    That didn't *really* help. It now just re-shows the first page when we do "open in new window" instead of showing "page cannot be displayed".

    So - outside of just generating normal HTTP GET links - any ideas?

    thanks,
    john

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is ability of the page to open in a new window a requirement, or you are trying to prevent an error if someone attempts to do it?
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Is using a button an option?
    Code:
    <input type="button" value="open record 35" onclick="goToDetail('35');" />
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New to the CF scene
    Join Date
    May 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Vladdy View Post
    Is ability of the page to open in a new window a requirement, or you are trying to prevent an error if someone attempts to do it?
    It's a "nice to have". Our target environment is actually IE 6, but with IE 7 and Firefox making tabs more popular, it would be swell if we could give people the option.

    We can prevent the error with the "return false" thing described at the bottom of the post, though all that does is take the user back to the page they're on.

    Quote Originally Posted by glenngv View Post
    Is using a button an option?
    Code:
    <input type="button" value="open record 35" onclick="goToDetail('35');" />
    I don't think so. I believe that for purely asthetic reasons they don't want buttons in their tables

    edit: oh yeah. You can't open a button click in a new window

    thanks,
    john
    Last edited by bluemorocco; 05-07-2007 at 04:11 PM.


  •  

    Posting Permissions

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