Welcome Guest ( Log In | Register )




                Web Hosting Guide

 
Reply to this topicNew Topic
Opening A Window (xhtml Valid Way), opening a window while being XHTML valid
overture
post Feb 14 2005, 02:55 PM
Post #1


Premium Member
Group Icon

Group: Members
Posts: 208
Joined: 6-September 04
From: England
Member No.: 315


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) {
[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.
Go to the top of the page
 
+Quote Post
chiiyo
post Apr 7 2005, 06:16 AM
Post #2


Premium Member
Group Icon

Group: Members
Posts: 218
Joined: 14-March 05
From: Singapore
Member No.: 3,041
myCENTs:92.74


So let me confirm this: there is no other way to open a new window without using Javascript under XHTML1.0Strict??
Go to the top of the page
 
+Quote Post
overture
post Apr 7 2005, 12:23 PM
Post #3


Premium Member
Group Icon

Group: Members
Posts: 208
Joined: 6-September 04
From: England
Member No.: 315


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
Go to the top of the page
 
+Quote Post
chiiyo
post Apr 7 2005, 05:44 PM
Post #4


Premium Member
Group Icon

Group: Members
Posts: 218
Joined: 14-March 05
From: Singapore
Member No.: 3,041
myCENTs:92.74


>_< 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?
Go to the top of the page
 
+Quote Post
overture
post Apr 10 2005, 03:08 PM
Post #5


Premium Member
Group Icon

Group: Members
Posts: 208
Joined: 6-September 04
From: England
Member No.: 315


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.
Go to the top of the page
 
+Quote Post
Hercco
post May 4 2005, 07:52 PM
Post #6


Super Member
Group Icon

Group: Members
Posts: 595
Joined: 4-September 04
Member No.: 228


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.
Go to the top of the page
 
+Quote Post
chiiyo
post May 5 2005, 02:11 PM
Post #7


Premium Member
Group Icon

Group: Members
Posts: 218
Joined: 14-March 05
From: Singapore
Member No.: 3,041
myCENTs:92.74


Sorry, Hercco, not really understanding what you wrote. What does that tag do??
Go to the top of the page
 
+Quote Post
overture
post May 9 2005, 02:16 PM
Post #8


Premium Member
Group Icon

Group: Members
Posts: 208
Joined: 6-September 04
From: England
Member No.: 315


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
Go to the top of the page
 
+Quote Post

Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts 11 FirefoxRocks 4,119 1st November 2009 - 07:31 PM
Last post by: iG-
No New Posts   5 turbopowerdmaxsteel 5,717 14th July 2009 - 12:10 AM
Last post by: iG-Kyryll
No New Posts   1 xboxrulz 324 7th February 2009 - 12:38 PM
Last post by: rnd-am
No New Posts   10 vizskywalker 3,064 4th December 2008 - 03:27 PM
Last post by: iG-Surfrock66
No New Posts   3 magiccode9 1,886 1st November 2008 - 05:53 PM
Last post by: faulty.lee
No New Posts   6 wutske 672 5th September 2008 - 11:11 PM
Last post by: docduke
No New Posts   13 mastercomputers 4,971 2nd September 2008 - 07:53 AM
Last post by: Quatrux
No New Posts 2 Ashraful 742 29th July 2008 - 02:35 AM
Last post by: faulty.lee
No new   31 WeaponX 4,246 27th July 2008 - 12:44 PM
Last post by: Habble
No New Posts   8 Coach 1,748 19th July 2008 - 10:47 AM
Last post by: Guest
No New Posts   8 affhotspot 3,383 29th May 2008 - 04:33 PM
Last post by: iGuest
No new   19 soleimanian 7,591 16th April 2008 - 02:35 PM
Last post by: java-area
No New Posts   0 FirefoxRocks 542 24th March 2008 - 05:42 PM
Last post by: FirefoxRocks
No New Posts   1 Rhúlio Victor 701 15th March 2008 - 05:39 PM
Last post by: yordan
No New Posts   4 Feelay 3,810 8th February 2008 - 05:43 AM
Last post by: TavoxPeru


Web Hosting Powered by ComputingHost.com.