Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Thursday, March 31, 2011

Using Javascript in the address bar

One easy way to run javascript in your browser is to, simply type:

javascript: and then a javascript function

So for example, if you want to change the term Christian Business into scams, just paste this into your address bar.

javascript: document.write(document.childNodes[1].innerHTML.replace(new RegExp(/Christian Business/gi), "scams").replace(new RegExp(/Christian Business/gi), "scams"))

To test this you could go here: http://www.google.com/search?hl=en&q=%22Christian+Business%22&aq=f&aqi=g10&aql=&oq=

And then just paste said javascript into the browser bar.

Sunday, December 14, 2008

Yahoo User Interface (YUI ) not working in Internet Explorer 6 , javascript error

I was working on Yahoo User Interface stuff and it wasn't working in internet explorer 6 and possibly seven. So the symptons were the page loaded fine, and there were no errors but my dialog panel wouldn't pop up. So upon closer examination, you could see that there was a javascript error, however as the page continued to load the warning sign went away. So I installed the microsoft script debugger for ie, and turned debugging on(both checkboxes). And it pointed me to a line similar to this that firefox was dealing with just fine:

YAHOO.company.container.panel1 = new YAHOO.widget.Panel("dialog-panel1", { width:"320px", visible:false, constraintoviewport:true, context:["link1","tl","bl", ["beforeShow", "windowResize"]], } );

However, when the script was cleaned up, and indented correctly it ran just fine.

{ context:["link2","tl","bl", ["beforeShow", "windowResize"]],
width:"320px",
visible:false,
constraintoviewport:true } );

**I couldn't put the whole solution because my blog template, screws with the spacing just ident the code so it all lines up as above and leave the YAHOO.company.container.panel1 = new YAHOO.widget.Panel("dialog-panel1",**

In my defense I didn't write the original script. The dialog pops up now it's just not displaying right, which is something wrong with our custom css, becuase the normal yahoo stuff looks like it would work just fine if rendered instead of ours. The day before I spent a significant amount of time troubleshooting an IE 6 problem where IE 6 had arbitrarily assigned values to either the padding or the margin I can't remember now, my fault for not documenting. The solution was to explicitly set the values in the style tag.

Saturday, December 13, 2008

New Job New Title Same Blog New Material

I have recently been hired on as a Perl and PHP programmer for a new start up. It's good to be off the freelance tit. They use CentOS servers so expect some CentOS/Redhat goodness coming your way. Along with perl,php,bash and javascript goodness(so far I have done a lot of javascript/css garbage{that's right, fuck you IE}). Oh and we use the Yahoo User Interface library so that's pretty cool to. So anyways, that being said I am going to try to get a couple technical posts out this weekend, and one during the week, and expect that to kind of be the interim blog schedule.

Oh and a new job, at least in my life, means a new computer, so I am leaning towards getting either a thinkpad or a macbook pro. If anyone wants to weigh in on that I would love to hear it.

Tuesday, July 15, 2008

JSON not working in PHP5?

If you are using PHP5 and JSON isn't working, and you compiled it or used a package manager the following switch may have been on --disable-all. To check do a phpinfo(); on your page and check. If it is on you need to recompile, without that switch. In FreeBSD you do that by editing the make file and taking out that line.

Saturday, May 31, 2008

AJAX tutorial for begginers

So ajax is a buzz word around the whole web 2.0 scene. It stands for Asynchronous JavaScript And XML. Basically it's just using some javascript to call a function called xmlHttpRequest(); .Anyway it's usually some pretty standard not changing code which you can get from the W3CSchools. I have made some slight modifications, that I find make the AJAX code work a little better.
What I did was write a simple stupid recursive function(smarm, I had been reading to much QC that week) that has a wait in it and a header thing, which I had to put in there due to some weird IE thing I still don't quite understand.
So this ajax code only does one little thing, it prints a diffrent page in a div every 5 seconds. Now the reason you would do this is if you had ever changing data in that html/php file, you put in the div. You also need onLoad="smarm()" in the body tag.


function ajaxFunction()
{
var xmlHttp;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById('stable').innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("POST","ajax2.php",true);
xmlHttp.send(null);
}
function smarm()
{
ajaxFunction();
var t=setTimeout("smarm()",5000);
http.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
}



So like ajax2.php might look something like this:

$handle = fopen('info.txt', 'a+');
$shiznit = fread($handle,600);
fclose($handle);

Or you could dump a mysql database table into an html table if that database was changing a lot.

Yeah and don't forget to add the div, in my example the div I used was "stable". So to do that you would just add div brackets with a class and id named stable. Also make sure you put the javascript in script brackets and the php in php brackets of course.

One caveat is that unless the page you are inserting into the div is somehow otherwise linked to your site, the content within it most likely well not be viewed by a search engine. So if you are building SEO intensive sites, be aware.



Friday, March 14, 2008

Firefox Web dev addons

Every hacker should have a web development add on. A lot of people like Firebug, but gmail complains about it. I personally have just used the Web Dev tool. I like it better and it may just be because it is the one I started with. But gmail doesn't bitch at me when I use it.