HREF="JavaScript:....... Help!

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

HREF="JavaScript:....... Help!

Post by Gen-ik »

I'm using a hyperlink to trigger off some JavaScript. I can't use any functions(), and I can't use any onclicks() etc.

I'm using this code..

Code: Select all

<a href="JavaScript:document.getElementById('bob').src='newbob.php';">change bob</a>
..which should replace a screen elements src with a new one.

BUT. Instead of changing the SRC like I want the entire page gets replaced with the newbob.php file.

Is there a way to stop this.. or is there something I've missed from the code?

I won't go into reasons why I need to do things this way but I do :)


Any help would be great. Thanks.
User avatar
d1223m
Forum Commoner
Posts: 80
Joined: Mon Mar 31, 2003 5:15 am
Location: UK, West Sussex

Post by d1223m »

i really wonder why u cant use functions or onclicks, please tell...

i tried some code

Code: Select all

<p id="bob">bob</p>
<a href="javascript:document.getElementById('bob').innerHTML='frank'; ">change</a>
but it doesnt work either *grin*

it does however work perfectly using onclick...
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Thanks.

I have got it sorted out now using a completely different method.

What I have done is found a way that allows me to include JavaScript files into a webpage without anyone being able to access them.

Keeping your JavaScript code secure and secret is 100% possible and I now know how to do it :wink:

Ah... and 'they' said it couldn't be done!
User avatar
d1223m
Forum Commoner
Posts: 80
Joined: Mon Mar 31, 2003 5:15 am
Location: UK, West Sussex

Post by d1223m »

how many browsers does it work in?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Gen-ik wrote:Keeping your JavaScript code secure and secret is 100% possible and I now know how to do it :wink:
So how does it work then?

Mac
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

As far as I know it seems to work fine with IE and NS. I haven't tested it on any other browsers yet.

Even if someone saves the webpage the script isn't saved with it, nor is it stored in the browsers cache, and the 'secure' script can also be included directly from a MySQL database which is very nice indeed :)

I think I'll keep things to myself for now though, but I'll be using it in any future websites I create for myself or for other people.
chris22
Forum Newbie
Posts: 11
Joined: Tue Apr 22, 2003 9:45 pm

Re: HREF="JavaScript:....... Help!

Post by chris22 »

NEVER NEVER NEVER do this!!!
Gen-ik wrote:

Code: Select all

<a href="JavaScript:document.getElementById('bob').src='newbob.php';">change bob</a>
The correct way to do it:

Code: Select all

<a href="url_for_no_js.html" onclick="return js_function()">
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Re: HREF="JavaScript:....... Help!

Post by []InTeR[] »

The correct way to do it:

Code: Select all

<a href="url_for_no_js.html" onclick="return js_function()">
The correct url for no js is #

Code: Select all

<a href="#" onClick="return js_function()">
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: HREF="JavaScript:....... Help!

Post by twigletmac »

[]InTeR[] wrote:The correct url for no js is #

Code: Select all

<a href="#" onClick="return js_function()">
No it's not - that prevents someone without JS from accessing the page:
Links and JavaScript Living Together in Harmony

There is no 'correct' way of doing this but there are definitely more accessible ways.

Mac
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

True,

I didn't read it well.

There is a page to go to.... With the onClick.

Sorry for the mistake.
Post Reply