In IE ok - but not in Opera and Firefox

P

pzi

Is anything significant not ok with my code?
It works in IE but not with any other browser. What did I wrong - I
dont see the point.

Thanks for any hints.


<script language='javascript'>

<!--
function CalcPrices(inPrice)
{
return (inPrice * 1.0 );
}

function PicID(inPrev,inNext)
{
location.href (inPrev + 1633 + "&fID=1086" + inNext);
}
//-->
</script>



<a
href='javascript:picID("Shop.asp?act=add&pID=","&prID=1004&pdetID=1301");'>
<script>document.write(Math.round(CalcPrices(155)))</script>
</a>
 
V

VK

pzi said:
Is anything significant not ok with my code?
It works in IE but not with any other browser. What did I wrong - I
dont see the point.
location.href (inPrev + 1633 + "&fID=1086" + inNext);

That was just recently dicussed in this group. If you open JavaScript
Console in Firefox (Tools>JavaScript Console) it will tell you the
exact reason: "location.href is not a function". And it's very true
because location.href is a /property/ you assign like location.href =
foo;

As the amount of users refusing to read any manuals out of principles
is traditionally very (confirmed by this post :) Microsoft in
violation of specs and against of their own MSDN documentation allows
to use location.href as a function call. It is a hack made for lazy
users by one careless producer so no other UA allows it.
 
E

Erwin Moller

pzi said:
Is anything significant not ok with my code?
It works in IE but not with any other browser. What did I wrong - I
dont see the point.

Thanks for any hints.

Hi pzi,

Some hints:
<script language='javascript'>

Do not use that. It is depricated for years now.
Use:
<script type="text/javascript">
instead.


I don't think you'll need to keep the <!-- up in your code these days.
All used browsers on the net handle javascript tags allright.
function CalcPrices(inPrice)
{
return (inPrice * 1.0 );
}

Not a very usefull function, but I guess this is just an example.
function PicID(inPrev,inNext)
{
location.href (inPrev + 1633 + "&fID=1086" + inNext);
}

try something like this instead

function PicID(inPrev,inNext)
{
var myLoc = "http://www.yoursite.com/" + inPrev + 1633 + "&fID=1086" +
inNext;
alert (myLoc);
// The alert is just for yourself to test of course.

location.href (inPrev + 1633 + "&fID=1086" + inNext);

That is strange Javascript, maybe wrong.
Try
location = myLoc;


}

//-->
</script>



<a
href='javascript:picID("Shop.asp?act=add&pID=","&prID=1004&pdetID=1301");'>
<script>document.write(Math.round(CalcPrices(155)))</script>
</a>


This is not advised. Do not use javascript in an URL.
Javascript is not a real protocol (like http or ftp).

It is often better to make a span with an onClick-handler, like this:
<span onClick="PicID(etc.etc);">Click me</span>

I think if you fix the suggested problems you'll be fine.


Regards,
Erwin Moller
 
T

Thomas 'PointedEars' Lahn

Erwin said:
I don't think you'll need to keep the <!-- up in your code these days.
All used browsers on the net handle javascript tags allright.

It was and is potentially harmful. Search the archives.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top