homepage Welcome to WebmasterWorld Guest from 184.73.87.85
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JS for non pop up link
Can someone please show me how?
Nick_W




msg:1477552
 7:17 am on Aug 1, 2002 (gmt 0)

Hi everyone,

I need to create some links that won't drain the PR out of my pages.

Could someone please show me how to create JS links that open in the same window?

Many thanks

Nick

 

rewboss




msg:1477553
 7:25 am on Aug 1, 2002 (gmt 0)

onclick="self.location='new_page.html';"

Or...

<a href="javascript:self.location='new_page.html';">

(You don't need to write "self". It simply refers to the containing window, and is included here for clarity.)

Nick_W




msg:1477554
 7:28 am on Aug 1, 2002 (gmt 0)

Smashing. Thanks rewboss. In the first example does the a not need an href? or is it just <a onclick=...>?

Nick

rewboss




msg:1477555
 8:24 am on Aug 2, 2002 (gmt 0)

I suppose, in the first example, the <a> tag doesn't require an href to work on most W3C-compliant platforms, but then it won't look like a hyperlink -- that's a usability issue. It really depends why you want this behaviour, or whether you are adding the event handler dynamically in a script, for example.

If you want to be really, really sneaky, you can write this:

<a href="dummy_url.html" onclick="location='real_url.html'; return false;">Click here to go there</a>

return false; makes doubly sure that the link does not go to dummy_url.html. The status bar will show "dummy_url.html" but the browser will end up at real_url.html.

There are a couple of interesting uses for this, one very cool, and one which could, potentially, be horribly misused.

SE's will most likely be directed to the URL in the href attribute, not the URL in the JavaScript. So you can direct search engines to one page, but browsers to a totally different page. That's probably really sneaky, and I refuse to be held responsible for whatever consequences may result.

The more useful application may be to direct JavaScript-enabled browsers to one page, and non-JavaScript-enabled browsers to another page. For example:

<a
href="non_js/newpage.html"
onclick="location='js/newpage.html'; return false;"
onmouseover="status='http://mydomain.com/js/newpage.html'; return true;"
onmouseout="status='';">Click here to go there</a>

(I included onmouseover and onmouseout handlers for reasons of user-friendliness.)

Note: I have actually seen a website with a link labelled "Click here to go there".

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved