Results 1 to 3 of 3

Thread: Use var in window.open

  1. #1
    Join Date
    Aug 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Use var in window.open

    Hi guys,

    Here's my code ... what I'm trying to do is use the var url in the window open statement...

    Code:
    // This is our javascript, which will pop up our message
    // in an alert box.
    
    function myfunction() {
    
    try {var url = gContextMenu.linkURL} // new FF, other?
    catch(e) {
       try {var url = gContextMenu.linkURL()} // old FF, SM, other?
       catch(e) {var url = String(gContextMenu.link)} // either FF, other?
    }
    window.open('http://mysite.com/?url=myfunction()','window name') 
    }
    It's also worth noting I've tried the following

    Code:
    function myfunction() {
    
    try {var url = gContextMenu.linkURL} // new FF, other?
    catch(e) {
       try {var url = gContextMenu.linkURL()} // old FF, SM, other?
       catch(e) {var url = String(gContextMenu.link)} // either FF, other?
    }
    window.open('http://mysite.com/?url=url','window name') 
    }
    and

    Code:
    function myfunction() {
    
    try {var url = gContextMenu.linkURL} // new FF, other?
    catch(e) {
       try {var url = gContextMenu.linkURL()} // old FF, SM, other?
       catch(e) {var url = String(gContextMenu.link)} // either FF, other?
    }
    window.open('http://mysite.com/?url=var url','window name') 
    }

    Can anyone help? I'm sure it's pretty simple but I'm a javascript newbie!

  2. #2
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    I think what you are looking for is this:

    Code:
    window.open('http://mysite.com/?url=' + url,'window name')
    The '+' appends the 'url' variable to the string.
    My site: FreshCut :)

  3. #3
    Join Date
    Aug 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks,

    I managed to figure this out last night (in my very tired state) before I saw this post, but thanks anyway!

    There's a new issue I'm battling with now though ... but I'll make a new thread for that one

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
  •