SmokingMan Posted May 27, 2006 Share Posted May 27, 2006 I want to use the .open() method to open new windows depending on the link clicked by the user. How do I change the URL parameter in the method depending on the link clicked, or do I need to set up a separate function for each link? I would think there would have to be a way to use one function and modify it for each link as needed. Or maybe use an if...else structure for the links?I'm open to suggestions. Link to comment Share on other sites More sharing options...
Webworldx Posted May 27, 2006 Share Posted May 27, 2006 function openWin( url ){ window.open( url , ............. );}Then use:<a href='...' onclick='openWin("http://my.url.com");'>Some Link</a> Link to comment Share on other sites More sharing options...
SmokingMan Posted May 27, 2006 Author Share Posted May 27, 2006 <a href='...' onclick='openWin("http://my.url.com");'>Some Link</a>I'm assuming that I still place the URL to be opened in the href attribute? Link to comment Share on other sites More sharing options...
Tony Posted May 27, 2006 Share Posted May 27, 2006 The URL to be opened is in the window should be in the brackets I believe. Link to comment Share on other sites More sharing options...
Webworldx Posted May 28, 2006 Share Posted May 28, 2006 I'm assuming that I still place the URL to be opened in the href attribute?<{POST_SNAPBACK}> The link should look more like:<a href='http://my.url.com' onclick='openWin("http://my.url.com"); return false;'>Some Link</a>This provides compatibility for people who don't have Javascript enabled to still access the URL Link to comment Share on other sites More sharing options...
reportingsjr Posted May 28, 2006 Share Posted May 28, 2006 why are you using javascript for this? your making it way harder than it is..<a href="http://my.url.com" target="_blank">some link</a>taadaa! Link to comment Share on other sites More sharing options...
scott100 Posted May 28, 2006 Share Posted May 28, 2006 why are you using javascript for this? your making it way harder than it is..<a href="http://my.url.com" target="_blank">some link</a>taadaa!<{POST_SNAPBACK}> First off target is deprecated (except in frames, so i read)Second, maybe he wants to open the window with certain dimensions and some toolbars disabled. Link to comment Share on other sites More sharing options...
reportingsjr Posted May 28, 2006 Share Posted May 28, 2006 it is? I did not know that.. sorry ( still works for me in all browsers) Link to comment Share on other sites More sharing options...
SmokingMan Posted May 28, 2006 Author Share Posted May 28, 2006 why are you using javascript for this? your making it way harder than it is..<a href="http://my.url.com" target="_blank">some link</a>I'm using JS because the "target" attribute has been deprecated. It may still work in all browsers, but it doesn't validate as XHTML Strict. This script will open a slideshow and I just want the window large enough to contain the show, so I have to control how the window displays. Link to comment Share on other sites More sharing options...
SmokingMan Posted May 28, 2006 Author Share Posted May 28, 2006 (edited) Okay...here goes. Here's the script I'm using: function openShow(url) {window.open('url',location=0,height=450,width=500,left=200,top=50,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0); } And here's the link I'm trying to open: <tr><td class="menu"><a href="http://testdomain.ftwin.com/albums/missy/missy-slideshow.html" class="child1" onmouseover="return addressMsg('Missy\'s Photo Slideshow')" onmouseout="return addressMsg('')" onclick="openShow('http://testdomain.ftwin.com/albums/missy/missy-slideshow.html');return false;">Missy's Slideshow</a></td></tr> In IE it opens a new window, but it opens as a full screen window with all of the attributes. All of my restrictions are ignored, and it's not a new separate window like I want it to be.In FF I get two new windows, but both have error messages. The first one opens to my specifications, with this message: Not FoundThe requested URL /url was not found on this server.Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. The other window is a new full screen window with this message: Not FoundThe requested URL /0 was not found on this server.Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. That's two windows with different errors. I haven't tried Opera yet, I'm afraid to see what happens there. Any ideas?If you want to try it, here's the link to the page. You'll want to go to Missy's Slideshow under Slideshows. Edited May 28, 2006 by SmokingMan Link to comment Share on other sites More sharing options...
scott100 Posted May 28, 2006 Share Posted May 28, 2006 Try this, window.open should have 3 parameters and if they are not variables be enclosed within quotes.window.open(url,""," location=0,height=450,width=500,left=200,top=50,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0") Link to comment Share on other sites More sharing options...
SmokingMan Posted May 29, 2006 Author Share Posted May 29, 2006 (edited) Well that worked...mostly. I now get the new separate window to open with my parameters, but the same window also opens in the current browser. So you end up with two browser windows open with the same page, but one is the first browser and the other is the one that conforms to the .open() parameters.I think I figured it out. I have the URL in the href attribute in the <a>...</a> and also in the onclick event. But if I remove it from the href, will the onclick still work if JS is disabled? Edited May 29, 2006 by SmokingMan Link to comment Share on other sites More sharing options...
scott100 Posted May 29, 2006 Share Posted May 29, 2006 (edited) That's weird, it worked ok for me.Make sure you have;onclick="openShow('http://testdomain.ftwin.com/albums/missy/missy-slideshow.html');return false;" I think I figured it out. I have the URL in the href attribute in the <a>...</a> and also in the onclick event. But if I remove it from the href, will the onclick still work if JS is disabled?Yeah that's because if the user has js disabled they can still access the page with html, so if you remove it they wont see anything. Edited May 29, 2006 by scott100 Link to comment Share on other sites More sharing options...
SmokingMan Posted May 29, 2006 Author Share Posted May 29, 2006 I found it. I forgot that pesky little space between the ; and return false;. Picky, picky, picky...It's working fine now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now