Page 1 of 1
HREF="JavaScript:....... Help!
Posted: Tue Apr 22, 2003 3:27 pm
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.
Posted: Wed Apr 23, 2003 8:13 am
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...
Posted: Wed Apr 23, 2003 9:11 am
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
Ah... and 'they' said it couldn't be done!
Posted: Wed Apr 23, 2003 9:27 am
by d1223m
how many browsers does it work in?
Posted: Wed Apr 23, 2003 10:11 am
by twigletmac
Gen-ik wrote:Keeping your JavaScript code secure and secret is 100% possible and I now know how to do it

So how does it work then?
Mac
Posted: Wed Apr 23, 2003 12:07 pm
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.
Re: HREF="JavaScript:....... Help!
Posted: Thu Apr 24, 2003 11:11 am
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()">
Re: HREF="JavaScript:....... Help!
Posted: Fri Apr 25, 2003 1:59 am
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()">
Re: HREF="JavaScript:....... Help!
Posted: Fri Apr 25, 2003 2:22 am
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
Posted: Fri Apr 25, 2003 2:24 am
by []InTeR[]
True,
I didn't read it well.
There is a page to go to.... With the onClick.
Sorry for the mistake.