Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help with Javascript code please

  • 09-02-2013 9:09am
    #1
    Registered Users, Registered Users 2 Posts: 751 ✭✭✭


    Hi all

    Just looking for some help if possible... I am trying to help my sister in Law out with scripting for her new website.....

    The idea is simple enough but i can not figure it out for the life of me and i have been trawling the web trying to find an answer but with no joy at ALL....

    What we need to happen is when a visitor to her website clicks on a text link, we want to display a message to the visitor and also open a new window for the visitor elsewhere on her site.....

    This is the code I have managed to come up with so far....


    <div id="hideaway" style="display: none;">
    <b>THIS IS THE HIDDEN TEXT</b></div>
    <a href="javascript:;" onClick="document.getElementById('hideaway').style.display='block';"window.open('http://www.rte.ie','popUpWindow','height=600,width=950,left=50,top=50,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');>Click For More Information....</a>

    If anyone could help me out I would really appreciate it..... Thanks
    Tagged:


Comments

  • Registered Users, Registered Users 2 Posts: 79 ✭✭leinad


    Hi all

    Just looking for some help if possible... I am trying to help my sister in Law out with scripting for her new website.....

    The idea is simple enough but i can not figure it out for the life of me and i have been trawling the web trying to find an answer but with no joy at ALL....

    What we need to happen is when a visitor to her website clicks on a text link, we want to display a message to the visitor and also open a new window for the visitor elsewhere on her site.....

    This is the code I have managed to come up with so far....


    <div id="hideaway" style="display: none;">
    <b>THIS IS THE HIDDEN TEXT</b></div>
    <a href="javascript:;" onClick="document.getElementById('hideaway').style.display='block';"window.open('http://www.rte.ie','popUpWindow','height=600,width=950,left=50,top=50,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes&#39;);>Click For More Information....</a>

    If anyone could help me out I would really appreciate it..... Thanks


    I think you are missing a few things: first window.alert("message"); to show the popup and you need to add a target attribute to the <a>.

    So it should read <a target="_BLANK"....


  • Registered Users, Registered Users 2 Posts: 751 ✭✭✭dozy doctor


    leinad wrote: »
    I think you are missing a few things: first window.alert("message"); to show the popup and you need to add a target attribute to the <a>.

    So it should read <a target="_BLANK"....

    I really appreciate your time taken to post your response, but now i am completely lost....

    Where do i insert the 'target='


  • Registered Users, Registered Users 2 Posts: 79 ✭✭leinad


    Ok I've reworked it a bit to clean it up

    This should do it

    <!DOCTYPE html>
    <html>
    <head>
    <script>
    function displayMessageAndOpenNewURL()
    {
    window.alert(document.getElementById('hideaway').innerText);
    window.open("http://www.google.ie", "_blank");
    }
    </script>
    </head>
    <body>
    <div id="hideaway" style="display: none;">
    <b>THIS IS THE HIDDEN TEXT</b></div>
    <a href="javascript:;" onClick="displayMessageAndOpenNewURL()">Click For More Information....</a>
    </body>
    </html>


  • Registered Users, Registered Users 2 Posts: 751 ✭✭✭dozy doctor


    leinad wrote: »
    Ok I've reworked it a bit to clean it up

    This should do it

    <!DOCTYPE html>
    <html>
    <head>
    <script>
    function displayMessageAndOpenNewURL()
    {
    window.alert(document.getElementById('hideaway').innerText);
    window.open("http://www.google.ie", "_blank");
    }
    </script>
    </head>
    <body>
    <div id="hideaway" style="display: none;">
    <b>THIS IS THE HIDDEN TEXT</b></div>
    <a href="javascript:;" onClick="displayMessageAndOpenNewURL()">Click For More Information....</a>
    </body>
    </html>

    Thanks a million Leinad

    Except what happens now is it opens a box which says 'undefined' and then when you click the box it closes and opens the url which is great...
    But is there anyway we can incorporate the hidden text into the script without opening the pop up box?


  • Registered Users, Registered Users 2 Posts: 751 ✭✭✭dozy doctor


    Figured it out another way.... What do you think?

    <i><span style="color: red;">Click to reveal text and open website</span></i>
    <div id="spoiler" style="display:none">
    This is the Hidden text
    </div>
    <button title="Click to show/hide content" type="button" onclick="if(document.getElementById('spoiler') .style.display=='none') {document.getElementById('spoiler') .style.display=''}else{document.getElementById('spoiler') .style.display='none'} window.open('http://www.rte.ie','popUpWindow','height=600,width=950,left=50,top=50,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes');&quot; >Get your code & Visit Website</button>


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 79 ✭✭leinad


    Thats fine, thought you wanted a popup, see JQuery for more advanced scripting, it wraps javascript, so you can simply do $("#spolier").show(); to show a div with an id of 'spoiler'

    see www.w3schools.com for easy tutorials and try it out sections to play with the code.


  • Registered Users, Registered Users 2 Posts: 751 ✭✭✭dozy doctor


    leinad wrote: »
    Thats fine, thought you wanted a popup, see JQuery for more advanced scripting, it wraps javascript, so you can simply do $("#spolier").show(); to show a div with an id of 'spoiler'

    see www.w3schools.com for easy tutorials and try it out sections to play with the code.
    Thanks again for all your kind help.... Will be sure to check out the website :)


  • Registered Users, Registered Users 2 Posts: 79 ✭✭leinad


    Thanks again for all your kind help.... Will be sure to check out the website :)
    No problem glad i could help


Advertisement