Forum Moderators: open

Message Too Old, No Replies

Open new windows w/out javascript?

         

jimshu79

5:46 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



I know sometimes search engines like javascript, sometimes they dont...And on my 'links' page i'm using javascript to open a new window when the user clicks on the link...example:

<a href="javascript:void(0)" onClick="MM_openBrWindow('http://www.example.com/','','')" onMouseOver="MM_displayStatusMsg('http://www.example.com/');return document.MM_returnValue" onMouseOut="MM_displayStatusMsg('');return document.MM_returnValue" style="text-decoration:none">example</a>

Question:
Can I use the "onclick" command without using javascript?
Does this usage of javascript hurt my webpage?

thanks...Jim

RonPK

6:04 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



May I suggest this solution:

<a href="ht*p://ww.example.com" onClick="window.open('ht*p://www.example.com', '', ''); return false" ...

This way the link can be used by browsers and SE bots with and without JavaScript enabled.

txbakers

6:32 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can I use the "onclick" command without using javascript?

no, onClick is a javascript event handler.

jimshu79

6:46 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



cool, i'll give it a shot right now...

jimshu79

6:46 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



oh.....so, unless i make a javascript link i can NOT use onclick?

bruhaha

6:47 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



onClick="MM_openBrWindow('http://www.example.com/','','')"

May I assume you are just simplifying the code for the sake of discussion? If not --if you really do not intend to specify any details about the window you are opening (such as size, location)-- then why are you even using javascript, and not just an ordinary HTML link?

If, on the other hand, you do specify them in your code, RonPK's solution is the way to go -- it will give exactly what you want for those who have javascript turned on, and the most important part for those who don't.

(And one minor addition/clarification to RonPK's script: since your intention is, presumably, to open a new window,remember to add the named target for those not reading javascript.)

[edited by: bruhaha at 7:01 pm (utc) on Feb. 9, 2004]

jimshu79

7:00 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



i see...so for a newbie who would like to add a piece of text, lets say: Example
and make it open a new window when clicked on, pointing to: ht*p://www.example.com ...

how should my code read for that?

DrDoc

7:04 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<a href="http://www.example.com" target="_blank" onclick="window.open('http://www.example.com','',''); return false;">Example</a>

:)

bruhaha

7:04 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



To keep it simple:

<a href="ht*p://www.example.com" target="_blank">Example</a>

(I see DrDoc's fingers move faster. And he did give you more complete code. But again, you only really need that if you plan to add other specifications about the window [height,width,location, which toolbars you wish to display or not]for your javascript-enabled users.)

[edited by: bruhaha at 7:07 pm (utc) on Feb. 9, 2004]

txbakers

7:05 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<a href="#" onClick="window.open('http://www.example.xxy','page','scrollbars=no')">Example</a>

jimshu79

7:10 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



Sweet =) it works great. I guess now I can go through my site and clean out all the 'javascript' the rest of the day!

thanks...
Jim

tedster

9:01 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to clarify a bit more, the onClick event handler automatically invokes javascript, so there is no need to use javascript: with it.

This doesn't mean you are not using javascript -- you are -- it's just that you do not need to invoke javascript with an explicit call because it's automatic with the event handler.

I think that point was causing some confusion earlier in this thread.

jimshu79

9:36 pm on Feb 9, 2004 (gmt 0)

10+ Year Member



I see, ok...but in the end, the code is cleaner and easier for the search engines, right?

Jim

DrDoc

10:56 pm on Feb 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main difference is that you're actually putting the URL in the href attribute. This means that both SEs and users with JS turned off will be able to follow the link.

It's like having a popup with alternative behavior :)