soycharliente Posted May 16, 2007 Share Posted May 16, 2007 Don't know if this is the place for this, so move it if it is necessary. How do you force a link to open in a new window while still being XHTML compliant (I'm using Transitional) and not using JavaScript? I can't find documentation that says using "target" is valid. I'd like to put that information inside <noscript> tags because I can do it with JS, I just would like to know how to, if it is possible, without JS. Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/ Share on other sites More sharing options...
john010117 Posted May 17, 2007 Share Posted May 17, 2007 Well, did you read anywhere that "target" is invalid? Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-255006 Share on other sites More sharing options...
ToonMariner Posted May 17, 2007 Share Posted May 17, 2007 Becasue it is 'invalid'!!!!!! In terms of standards compliance opening a new window is considered a document effect and as such shoudl be controlled by javascript. Here is a bit of code that will help in this respect in an accessible mode. first the html... <a class="newwindow" href="/path/to/page" title="Link Title" onclick="window.open(this.href); return false;" onkeypress="window.open(this.href); return false;">Link Text</a> a bit of css. // this hides the text if js is on. a.newwindow span { position: relative; left: -5000px; width: 0; height: 0; overflow: auto; /* may need display block or a float to ensure no space is taken up when rendering */ } and finally a bit of js to add the 'opens in new window text' this only appears if JS is on. function newwindowA() { var as = document.getElementsByTagName('a'); for(var i=0;i<as.length;i++) if (as[i].className == 'newwindow') { as[i].innerHTML += ' <span class="hidden">(new window)</span>'; as[i].style.padding = '0px 17px 0px 0px;'; as[i].style.background = background: transparent url(/global/images/new-window-icon.gif) no-repeat right center;'; } return; } If js is off then the page shoudl open in teh same window nad neither the newwidow icon of the text should show. If js is on then the opens in newwindow text is shown and if css is on the txt will be hidden and the icon shown... This is an alteration to some code I have so the style.background may require separate lines of code for each value.. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-255309 Share on other sites More sharing options...
soycharliente Posted May 17, 2007 Author Share Posted May 17, 2007 So there is no way to open a new window without using JS that also is valid standard compliant code? It just looks like you gave me a bunch of JS, which I already have (see, the smiley - lol) Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-255358 Share on other sites More sharing options...
ToonMariner Posted May 17, 2007 Share Posted May 17, 2007 well.... If you use target="_blank" browsers will still open a new window - they don't implement as strictly as they should, but in terms of standards compliance document effects should be js controlled. Browsers (IMO) should apply the standards to the recognized doctypes so in that sense xhtml 1.1 should never open a new window without js. Before others have their two penneth - remember we can CHOOSE which dtd we use - if we CHOOSE to use a strict one we should stick to it - that is what the web standards project is trying to help achieve... Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-255373 Share on other sites More sharing options...
KnottyAlder Posted May 17, 2007 Share Posted May 17, 2007 The only problem with using JavaScript is that ability user have in turning it off. I'm of the opinion that if they're stupid enough to turn something as well used JavaScript off then they deserve broken pages. But this problem isn't the best thinking if you're getting paid for your work. Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-255519 Share on other sites More sharing options...
ToonMariner Posted May 17, 2007 Share Posted May 17, 2007 Hence all the stuff about js being on or off in my post!! Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-255607 Share on other sites More sharing options...
soycharliente Posted May 17, 2007 Author Share Posted May 17, 2007 I validated a page using the target attribute under transitional (and no I didn't switch to it, lol) and it didn't generate any errors. So would you recommend doing something like this? <script type="text/javascript"> document.write("<a href=\"javascript:window.open('info.html');\" title=\"view detailed info\">more info</a>"); </script> <noscript><a href="info.html" target="_blank" title="view detailed info">more info</a></noscript> Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-255841 Share on other sites More sharing options...
ToonMariner Posted May 17, 2007 Share Posted May 17, 2007 if you are validation using a transitional dtd then why not just leave the target="_blank"? if you are developing to the standards and using someting like xhtml 1.1 (Personally I use that all the time now) then what I originally posted will do what you need. document.write is not considered acceptable though - validators don't pick it up but you should use document.getElementById('element') as the object identifier and then set it properties... e.g. document.getElementById('element').innerHTML Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-255944 Share on other sites More sharing options...
soycharliente Posted May 17, 2007 Author Share Posted May 17, 2007 EDIT: I typed something and then changed my mind. I wish I could delete this. Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-255962 Share on other sites More sharing options...
soycharliente Posted May 18, 2007 Author Share Posted May 18, 2007 @toon: I decided to switch my DOCTYPE to XHTML 1.1 and boy was that interesting. Anyway, moving on. After I got rid of all the errors, I tried to go back and use your JS example code from earlier down the thread. I don't quite understand something though. If JS is off, how does the new page open? Will it just use the current page or will it actually open up a new window? Earlier thread stuff so you don't have to scroll so much: Becasue it is 'invalid'!!!!!! In terms of standards compliance opening a new window is considered a document effect and as such shoudl be controlled by javascript. Here is a bit of code that will help in this respect in an accessible mode. first the html... <a class="newwindow" href="/path/to/page" title="Link Title" onclick="window.open(this.href); return false;" onkeypress="window.open(this.href); return false;">Link Text</a> a bit of css. // this hides the text if js is on. a.newwindow span { position: relative; left: -5000px; width: 0; height: 0; overflow: auto; /* may need display block or a float to ensure no space is taken up when rendering */ } and finally a bit of js to add the 'opens in new window text' this only appears if JS is on. function newwindowA() { var as = document.getElementsByTagName('a'); for(var i=0;i<as.length;i++) if (as[i].className == 'newwindow') { as[i].innerHTML += ' <span class="hidden">(new window)</span>'; as[i].style.padding = '0px 17px 0px 0px;'; as[i].style.background = background: transparent url(/global/images/new-window-icon.gif) no-repeat right center;'; } return; } If js is off then the page shoudl open in teh same window nad neither the newwidow icon of the text should show. If js is on then the opens in newwindow text is shown and if css is on the txt will be hidden and the icon shown... This is an alteration to some code I have so the style.background may require separate lines of code for each value.. Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-256026 Share on other sites More sharing options...
ToonMariner Posted May 18, 2007 Share Posted May 18, 2007 If js is off then the page will open in the current window - just as the standards say it should... the js is to both open the window and let the user know that the link will open a new window. if js os off then the user will not be told that a new widnow is about to open nor will a new window open. Quote Link to comment https://forums.phpfreaks.com/topic/51746-solved-open-new-window/#findComment-256057 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.