Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript issues 2

Status
Not open for further replies.

edifreak

IS-IT--Management
Apr 7, 2003
74
AU
Greetings,

I'm having trouble embedding javascript open.window in my code. I think I've made some kind of error in formulating the statement. can anyone help?

cout << "<a href=\"javascript:\"onclick=\"JavaScript window.open(link, 'profile', toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=590,height=425')\"> </a>";

The variable 'link' is a input that is captured from a form.

i'm gettin parse error?
thanks in advance
 
edifreak,

Code:
cout << "<a href=\"javascript:void(0)\" onclick=\"window.open(link, 'profile','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=590,height=425')\"> test </a>";

Of course, link has to be defined before it can be used above.
But you've probably got a handle on that.

Hope it's helpful.

Lrnmore
 
Thanks Lrnmore for your help.

i'm still getting the parse error...i've even replaced the variable link with an url.

cout << "<a href=\"javascript:void(0)\"onclick=\"window.open(' 'profile','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=590,height=425')\"> test </a>";
 
pls ignore my error. it all works now :D
thanks again!
 
just one more question... if i want to output the contents of the link variable as the url then should the following code do the trick?

cout << "<a href=\"javascript:void(0)\"onclick=\"window.open(\" "<< link <<" \", 'profile','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=590,height=425')\"> test </a>";
 
I was making an assumption in my post, that link was a javascript variable defined at the client.

Is this the case? OR Is it a C variable defined at the server?


You should include a space here:
Code:
\"javascript:void(0)\" onclick=

If it is a server side variable give this a try:
Code:
cout << "<a href=\"javascript:void(0)\" onclick=\"window.open('"<< link <<"', 'profile','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=590,height=425')\"> test </a>";

Lrnmore
 
Lrnmore, i awarded a star for ya for being patient with me :D
 
Lrnmore, i now have problem in executing the script under IE! it worked fine with opera... but IE is spitting out javascript syntax errors.. its not liking the way i formed the javascript statement.

i tried various alternatives
javascript:void(0)
javascript:void()
javascript:

no luck? any tip?
Thanks!
 
edifreak,

Try this page in your IE, I would be surprised to see errors:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
</head>
<body>
<a href="javascript:void(0)" onclick="window.open('[URL unfurl="true"]http://www.google.com','profile','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=590,height=425')">[/URL] test </a>

</body>
</html>

But as an alternative you can use the "#" in place of "javscript:void(0)"
As in,
Code:
<a href="#" onclick="window.open('[URL unfurl="true"]http://www.google.com','profile','toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=590,height=425')">[/URL] test </a>

Shout back if it doesn't work out, I'd really like to hear if the test
page above gives you errors in IE.

You might also post the page (client side) source code of the offending page.

Thanks,
Lrnmore

Thanks Paul for the *
 
using the "#" in place of "javscript:void(0)" worked!

also yes, the test page worked as a standalone html.

i will try including the below code in my c script and see if javscript:void(0) works then.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

But for now, everything works. THanks again for ur valuable tip!
 
Lrnmore,
you're welcome and deserving ...



cigless ...
 
I have been pulling my hair out over this problem for quite some time now. I have no idea why it is not working, have 2 different implementations of the same thing. It is working under firefox/netscape, but not IE.

Code:
<SCRIPT LANGUAGE="JavaScript">
function openwindow(url,ref,windowprop) {
	window.open(url,ref,windowprop);
}
</SCRIPT>

<form action="javascript:openwindow('viewitem.php?realm=Midgard&slot=Chest','Navajo Inventory Management','height=300,width=550,scrollbars=no')">
<input type="submit" value="Change Item"></form>

<form action="#" name="form1">
<input type="submit" onClick="javascript:window.open('scarmorform.php?realm=Midgard&slot=Chest','Navajo Inventory Management',config='height=300,width=320,scrollbars=no')" value="SC Item"></form>

Both of those forms do not work correctly, I still do not know why, any help would be greatly appreciated. I am thinking it just hates the form :(

 
edifreak,

Thanks for the * and getting back with the results.

ToastMaster,

IMHO you are asking too much to happen at the same time.
You have forms being submitted and javascript trying to perform it's
task. One thing I would point out is that javascript runs
from an "established window" when your forms "submit" the current
DOM is destroyed. Wheter or not that is the problem I can't
say for sure.

My first question is, Why are you using forms?
Most folks use new windows because they want the "opener" to
maintain some "state" for reference.

Maybe you could describe what you are trying to accomplish.

Lrnmore
 
Now that I think about it, the forms aren't really needed because I can just use the php (what is generating the page) to append the information I need to pass onto the page that is being opened. Let me try that instead, thanks for the idea :) hopefully it doesn't flip out on me.
 
Code:
<SCRIPT LANGUAGE="JavaScript">
function openwindow(url,ref,windowprop) {
	window.open(url,ref,windowprop)
}

<a href="#" onClick="javascript:openwindow('scarmorform.php?realm=Midgard&slot=Arms','Navajo Inventory Management',config='height=300,width=320,scrollbars=no')">
blah</a>

Having same problem when I take it out of the form now =/. I need to pass that information in the link up. I have the ability to snag it and put it into the link when the page is generated, so the form isn't necessary. I am wondering why that doesn't work correctly, are any of the characters wierd?
 
ToastMaster,

In the function openwindow you have 3 arguments that the function is expecting:
url, ref, windowprop

Code:
<SCRIPT LANGUAGE="JavaScript">
function openwindow(url,ref,windowprop) {
    window.open(url,ref,windowprop)
}

<a href="#" onClick="javascript:openwindow('scarmorform.php?realm=Midgard&slot=Arms','Navajo Inventory Management',config='height=300,width=320,scrollbars=no')">
blah</a>

Try passing the arguments like this:
Code:
<a href="#" onClick="javascript:openwindow('scarmorform.php?realm=Midgard&slot=Arms','Navajo Inventory Management','height=300,width=320,scrollbars=no')">
blah</a>

HTH
signing off now zzzz...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top