Opening A Window (xhtml Valid Way) - opening a window while being XHTML valid

free web hosting
Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > HTML, XML and other Markup Languages

Opening A Window (xhtml Valid Way) - opening a window while being XHTML valid

overture
This is going to be an extremely simple tutorial for you all. I know many people still don't understand XHTML in the respect of "why use it", but this tutorial is not to explain to you why, i believe mastercomputers explained it all in another topic. This topic is to tell you how to open another window while being XHTML 1.0, 1.1 valid.

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 '>' wink.gif ).

This is the simple Javascript function we will be using:

CODE

function launchit(url) {
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.

 

 

 


Reply

chiiyo
So let me confirm this: there is no other way to open a new window without using Javascript under XHTML1.0Strict??

Reply

overture
as far as i know... no. although i haven't searched the web for other ways if there are any. javascript would still be needed to be used as this is the only way to open another window as the "target="_blank"" has been removed. it is an easy way none the less. smile.gif

Reply

chiiyo
>_< I'm taking the easy way out, writing (off-site) next to all the links I used to make pop into new windows, and writing a line in my introduction that says that all links marked with (off-site) lead out of the site and visitors are advised to open them in new windows.

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?

Reply

overture
yeah. you can still open in a new tab by doing the usual process and you can also use shift + click to open in a new window also. the Javascript code does not remove any other way of doing opening the website/page. it is just a replacement method for people who want to be Strict in their coding.

Reply

Hercco
There is a way open links in new window without Javascript and using valid XHTML.

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.

Reply

chiiyo
Sorry, Hercco, not really understanding what you wrote. What does that tag do??

Reply

overture
Herrco i tried this before and it never worked. Like you said it shows the "]>" at the top of the page which if you have something which needs to be positioned right at the top then it will be moved out of place. it did not even open the links in a new window. i had this answer in an old forum i was at before i came to this one and still it didn't work. i still think the little bit of Javascript is best and most efficient way as it works absolutely perfectly biggrin.gif

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. valid pop ups xhtml _target - 6.32 hr back. (1)
  2. xhtml valid javascript new window - 21.02 hr back. (1)
  3. easiest way to open a new window - 21.09 hr back. (1)
  4. href new window xhtml - 42.18 hr back. (1)
  5. xhtml opening link in new tab - 52.52 hr back. (1)
  6. how to open a website without a href tag in javascript - 71.83 hr back. (1)
  7. open links in new tab xhtml - 92.65 hr back. (1)
  8. open new window xhtml tag - 96.42 hr back. (1)
  9. how to link new window valid - 101.12 hr back. (1)
  10. xhtml to open new windows - 104.75 hr back. (1)
  11. d3dwindower window vista - 107.96 hr back. (1)
  12. xhtml and url open in new window - 110.06 hr back. (1)
  13. xhtml javascript window target - 121.60 hr back. (1)
  14. xhtml open page in new tab - 132.46 hr back. (1)
Similar Topics

Keywords : opening, window, xhtml, valid, opening, window, xhtml, valid

  1. Rss And Xhtml From The Same Data
    A simple way (0)
  2. XHTML: Separating Design From Content
    Get rid of those bad habits... (5)
    Knowing what XHTML is set out to do You may think that coding your site to meet XHTML
    standards requirements makes you look as if you are keeping up with your web page but unless you
    know what XHTML job is, then you can look like a fool. For years, web browsers were designed to
    open one page and show it in a human understandable fashion. But, although not as well known,
    another mark up language has been floating around called XML. XML was made to separate what content
    there was, from how the content is meant to look. When you go to a site, you are looki....
  3. Converting HTML over to XHTML
    Crossing over to the darkside (13)
    Allow for alterations Well, I've just had to convert another HTML 4.01 Transitional website
    over to XHTML (eXtensible HyperText Markup Language) 1.0 Transitional, I will later on convert over
    to XHTML 1.0 Strict as soon as I write the CSS (cascading stylesheet) file for it but it had to be a
    quick update and removing all presentational elements and placing them in a CSS file is not quicker
    than just altering some tags. So this is where I got the idea to write a How to Convert HTML over
    to XHTML . Let's begin I'm having trouble knowing where to start ....

    1. Looking for opening, window, xhtml, valid, opening, window, xhtml, valid

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for opening, window, xhtml, valid, opening, window, xhtml, valid
advertisement




Opening A Window (xhtml Valid Way) - opening a window while being XHTML valid



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE