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
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy how to open my daily links in a new window

    I am completely a beginner at coding and really do not know much right now.

    This is the day of week link rotation script which works just great:

    Code:
    <script type="text/javascript">
    <!--
    var MyEveryDayLinks = [
    ['Sunday', 'http://www.google.com', 'Google'],
    ['Monday', 'myURL', 'LinkName'],
    ['Tuesday', 'myURL', 'LinkName'],
    ['Wednesday', 'myURL', 'LinkName'],
    ['Thursday', 'myURL', 'LinkName'],
    ['Friday', 'myURL', 'LinkName'],
    ['Saturday', 'myURL', 'LinkName']
    ];
    var today = new Date();
    var L = today.getDay();
    document.write('Today is ' + MyEveryDayLinks[L][0] + '. My daily 
    
    URLs: <a href="' + MyEveryDayLinks[L][1] + '">' + 
    
    MyEveryDayLinks[L][2] + '<\/a>.') ;
    // -->
    </script>
    Unfortunately I can't open urls in a new window.

    I would so like this to work...but don't know why i can't make it work.

    I've tried something like this with no luck...any ideas?:

    Code:
    <a href="javascript:[window.open(' + MyEveryDayLinks[L][1] + ', 'height=200, width=200',)];">' + MyEveryDayLinks[L][2] + '<\/a>.') ;

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Opening URLs can be done by using target="_blank":
    Code:
    document.write('Today is ' + MyEveryDayLinks[L][0] + '. My daily URLs: <a href="' + MyEveryDayLinks[L][1] + '" target="_blank">' + MyEveryDayLinks[L][2] + '<\/a>.');
    However, if you insist on using window.open, you can do so with:
    Code:
    document.write('Today is ' + MyEveryDayLinks[L][0] + '. My daily URLs: <a href="#" onclick="window.open(\''+MyEveryDayLinks[L][1]+'\',\'windowName\',\'height=200, width=200\');return false;">' + MyEveryDayLinks[L][2] + '<\/a>.');
    PS: Have a look into methods in DOM like document.createElement(), document.appendChild() etc (instead of document.write()). Google for them and similar ones.

    Let us know if you need further assistance.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    Regular Coder
    Join Date
    Mar 2008
    Location
    London
    Posts
    152
    Thanks
    4
    Thanked 42 Times in 42 Posts
    option 1:
    Code:
    <a href="http;//www.google.com" target="_blank">Google</a>
    option 2:
    Code:
    <a href=":;" onclick="window.open('http://www.google.com','','height=200,width=200')">Google</a>

  • #4
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks lots rangana, you have made my Day!

    thanks thanks thanks


  •  

    Posting Permissions

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