Jump to content

Code Help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Howdy_McGee

Howdy_McGee

    Programmer

  • Members
  • PipPipPipPip
  • 135 posts
var browserName=navigator.appName;
var element=getElementById("socialContainer");
if (browserName=="Microsoft Internet Explorer")
{
function style(onload)
{
element.style.padding-right="100px";
}
}

I am making a script so that only in Internet Explorer it moves the socialContainer id over from the right 100px

this all looks right to me but I dont know javascript all too well so idk. Wondering if you guys could help me.

#2
bmett

bmett

    Newbie

  • Members
  • PipPip
  • 12 posts
hmm why don't you check the browser version with PHP? That's how I always do it:
<?php

echo($_SERVER[‘HTTP_USER_AGENT’]);

?>
This gives you the Browser Version. Here is a list of possible outputs:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) 

Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC)

Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0

You can find a complete list here:http://www.pgts.com....rowser_list.txt.
This way you can very easily check the browser and do different actions for different browsers.

Cheers,
Bjorn

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
Well, a more ideal way you would do it like Bjorn suggested, would be using PHP's stripos function.

if (stripos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
   print "function style(onload)
               {
                  element.style.padding-right='100px';
           }"; //Internet Explorer-specific code
}


#4
bmett

bmett

    Newbie

  • Members
  • PipPip
  • 12 posts
That's exactly what I meant Nullw0rm :)

I just wanted to give McGee a push in the right direction. ^^

Cheers,
Bjorn

#5
NastyDevil

NastyDevil

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
Here is what you are looking for i believe. Also if you want to use padding you need to do it to the left of the object to shift it to the right.
<html>

<head>
<script type="text/javascript">
function mover()
{
var browserName=navigator.appName; 
if (browserName=="Microsoft Internet Explorer")
{ 
document.getElementById('cont').style.position="relative";
document.getElementById('cont').style.left="100";
}
}
</script>
</head>


<body onload="mover()">

<div id="cont">Hello there</div>


</body>
</html>

Oh and I was trying to figure this out for a while until I realized that it needs to have a relative position; it has to be relative to move.

#6
Howdy_McGee

Howdy_McGee

    Programmer

  • Members
  • PipPipPipPip
  • 135 posts
:/ see I don't understand PHP... I understand a fair amount of javascript so that's why i'd rather go that route.