Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 5th, 2005, 09:13 AM
Registered User
 
Join Date: Aug 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Open a new window from an anchor - JSP

I'm simply trying to open a new window with a picture when the user clicks on an image from within a JSP page.

Code:
function openNewWin(linkURL) {
window.open(""+linkURL+"", "", "scrollbars, top="+winTop+", left="+winLeft+", height="+winHeight+", width="+winWidth+"");
}

var linkURL = "/TestSite/jsp/showPhoto.jsp"
document.write('<tr><td align="center"><a href="javascript:openNewWin('+ linkURL +');">');
I've tried about 10 different configurations and I can't get any of them to work. Any suggestions?
 
Old August 5th, 2005, 11:01 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Perhaps you have a popup blocker?
In any case try adding this to see if you call looks valid:
Code:
function openNewWin(linkURL)
{
var sFeatures = "scrollbars, top="+winTop+", left="+winLeft+", height="+winHeight+", width="+winWidth+"";
alert(linkURL + "\n" + sFeatures);
window.open(""+linkURL+"", "", sFeatures);
}
Normally "scrollbars" has "=yes" or "=no" for example.
Your <a> element should also be:
Code:
<a href="javascript:openNewWin('/TestSite/jsp/showPhoto.jsp');">...</a>
in the source of the page, use view source to check, I think your quotes are missing.
Also try a simple window.open(linkURL) on its own.

--

Joe (Microsoft MVP - XML)
 
Old August 5th, 2005, 11:27 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

HIII,
Try this
hope u will get the solution
<script language="javascript">
function openNewWin() {
window.open(linkURL)
}

var linkURL = '/TestSites/showPhoto.html'
str ="<a href= \"javascript:openNewWin('+linkURL+')\">LoginHer e</a>";
document.write(str)
</script>


Cheers :)

vinod
 
Old August 5th, 2005, 11:45 AM
Registered User
 
Join Date: Aug 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys!

I tried your suggestions and I got it to work...
I guess I didnt need to pass the linkURL variable into the openNewWin() Function.

I removed the parameter, and it worked perfectly:

function openNewWin() {
var sFeatures = "scrollbars, top="+winTop+", left="+winLeft+", height="+winHeight+", width="+winWidth+"";
window.open(""+linkURL+"", "", sFeatures);
}

var linkURL = "/TestSite/jsp/showPhoto.jsp"
document.write('<tr><td align="center"><a href="javascript:openNewWin();">');
document.write('<IMG src="/TestSite/images/'+ photo +'" width="190"></a></td></tr>');

I think Joe was right, the quotes were getting screwed up somewhere.


Best Regards,

Josh
 
Old August 5th, 2005, 11:58 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:I guess I didnt need to pass the linkURL variable into the openNewWin() Function.
That's because linkURL is global variable so the function can read it without it being a parameter.

Using javascript URLs is not a good idea anyway, it stops people without JavaScript using the site. Better to use this which degrades gracefully:
Code:
<a href="/TestSite/jsp/showPhoto.jsp" onclick="openNewWin(this.href); return false;">Show Photo</a>
Obviuosly though if you are using document.write users without JavaScript have had it anyway...
If you are using JSP you don't need document.write, why not produce the page on the server?

--

Joe (Microsoft MVP - XML)
 
Old August 5th, 2005, 12:32 PM
Registered User
 
Join Date: Aug 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe,

The opener page is actually an HTML page with JavaScript. I guess I called it a JSP page in my original post; I think I'm retarded or something. My webapp is inside a firewalled intranet with locked workstation configurations and everyone has javascript enabled; So I don't need to worry about that for this application. I did change the anchor tag as you suggested though, that's much better form. Thanks for the advice and help.

Best Regards,
Josh





Similar Threads
Thread Thread Starter Forum Replies Last Post
window.open() ckrajeshvarma ASP.NET 2.0 Professional 5 August 16th, 2006 09:13 AM
JSP popup window Anuja Pro JSP 0 March 15th, 2006 07:01 AM
Open New Window b_camp Classic ASP Basics 2 May 12th, 2005 01:19 AM
Open in new window sridevi Excel VBA 1 November 4th, 2004 06:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.