PDA

View Full Version : Use var in window.open



DoA
08-07-2009, 08:22 PM
Hi guys,

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




// 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



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



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!

jlizarraga
08-07-2009, 11:33 PM
I think what you are looking for is this:


window.open('http://mysite.com/?url=' + url,'window name')

The '+' appends the 'url' variable to the string.

DoA
08-08-2009, 04:54 PM
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