|
|
Opening A Window (xhtml Valid Way) - opening a window while being XHTML valid | ||
Discussion by overture with 7 Replies.
Last Update: May 9, 2005, 2:16 pm | |||
![]() |
|
|
I will be using Javascript so you can either put the code in an external file and link to it (remember to add the '/' before the '>'
This is the simple Javascript function we will be using:
CODE
function launchit(url) {[tab][/tab]window.open(url);
}
This function when called upon will create and open a window which will take you to the website which has been given.
The above code has a variable within it called 'url', this is so that it knows that something is going to be used in order for the function to work correctly, in this case a website address.
This is the code to use it correctly:
CODE
<a href="http://overture.uni.cc" onclick="launchit('http://overture.uni.cc'); return false;">Some Link</a>As you can see the function is called upon using the onclick event within the anchor tag. I hear you say "what does the 'return false' do". This basically stops the focused window (the window which the link is on) to not go to that website as we want it to open in another window (that is the whole point of this tutorial).
The normal way to do this would be to use this code:
CODE
target="_blank"This would open the window getting the url from within the href="".
This however is not valid XHTML and will return and error when it is checked. This is because the 'target' attribute is not supported in XHTML 1.0 or 1.1. I do believe it is in XHTML TRANSITIONAL (could someone verify that for me).
Well that is it. I believe this all works correctly. If not tell me the problem and i will try and correct yours or my mistake.
overture.
Does away with the whole target and javascript thing. Sometimes the easiest ways are the least thought-off...
By the way, just asking, would this particular javascript still allow people to open the window in a new tab or other similar shortcuts? As in would it override all other ways of opening the site?
You can add more methods to XHTML. You can either load a DTD supporting target or add it to it inside the <!DOCTYPE>
What to add is:
CODE
[ <!ATTLIST a target CDATA #IMPLIED> ]Notice that most browsers (including geckos and IE) show "]>" at the top of the page. This sucks but you can hide it using CSS change it to background-color. Also I believe it will disappear from Geckos at least. Opera does not show it.
Similar Topics:
Php/xhtml Pages
Problem With Xhtml Validation
Xhtml Validation With Php In Cgi Mo...
Converting HTML over to XHTML Crossing over to the darkside (13)
|
(7) HTML 101 - Web Design For Beginners Absolute Basic HTML Writing
|
HOME 






