Omnimaga
General Discussion => Technology and Development => Web Programming and Design => Topic started by: Sorunome on April 03, 2012, 08:14:04 am
-
Ok, I decided to launch a thread with webdeveloping questions as I have so many questions....I just like programming stuff for my website :D
Well, first of all, is it possible to open a link in a new tab with Javascript?
Second...Well, I want to store pics in an array (Javascript), the pics are the canvas pics, it is generated dynamic by php, and want that the nexxt pic won't start loading before the one before was finished.
I wrote this:
<?php
if ($handle = opendir($folder))
{
echo "pics = new Array();";
$pics = array();
while (false !== ($entry = readdir($handle)))
{
if (preg_match("/[^\.].*\.(jpg|jpeg|png|gif)$/i", $entry))
{
array_push($pics,$entry);
}
}
closedir($handle);
sort($pics);
$j = 0;
foreach ($pics as &$pic)
{
echo "function pic$j () {
pics[$j] = new Image();
pics[$j].src = '$folder/$pic';
pics[$j].";$j++;echo"addEventListener('load',pic".$j.",false);
}\n";
}
echo "function pic".$j." () {};\n\n\n";
}
?>
Well, the errorkonsole of firefox gives me this:
[14:06:08.411] uncaught exception: [Exception... "The type of an object is incompatible with the expected type of the parameter associated to the object" code: "17" nsresult: "0x80530011 (NS_ERROR_DOM_TYPE_MISMATCH_ERR)" location: "[no need to know]"]
Please help me!
-
What's the generated code look like?
-
<!DOCTYPE html>
<html><head>
<script type="text/javascript">
pics = new Array();
function pic0 () {
pics[0] = new Image();
pics[0].src = '../../knex/ballmachines/crazy/pics/FCLAHGTGD2J1W43.LARGE.jpg';
pics[0].addEventListener('load',pic1,false);
}
function pic1 () {
pics[1] = new Image();
pics[1].src = '../../knex/ballmachines/crazy/pics/FI0ABR4GD2JC4X3.LARGE.jpg';
pics[1].addEventListener('load',pic2,false);
}
function pic2 () {
pics[2] = new Image();
pics[2].src = '../../knex/ballmachines/crazy/pics/FODHF3KGD2JJN69.LARGE.jpg';
pics[2].addEventListener('load',pic3,false);
}
function pic3 () {
pics[3] = new Image();
pics[3].src = '../../knex/ballmachines/crazy/pics/FRG66RIGD2J1W44.LARGE.jpg';
pics[3].addEventListener('load',pic4,false);
}
function pic4 () {
pics[4] = new Image();
pics[4].src = '../../knex/ballmachines/crazy/pics/FSRATY0GD0R0CV4.LARGE.jpg';
pics[4].addEventListener('load',pic5,false);
}
function pic5 () {
pics[5] = new Image();
pics[5].src = '../../knex/ballmachines/crazy/pics/FTWRI1CGD2JC4X6.LARGE.jpg';
pics[5].addEventListener('load',pic6,false);
}
function pic6 () {
pics[6] = new Image();
pics[6].src = '../../knex/ballmachines/crazy/pics/FYQYILGGD2JC4X5.LARGE.jpg';
pics[6].addEventListener('load',pic7,false);
}
function pic7 () {
pics[7] = new Image();
pics[7].src = '../../knex/ballmachines/crazy/pics/FZMZ8OBGD0R0CVA.LARGE.jpg';
pics[7].addEventListener('load',pic8,false);
}
function pic8 () {
pics[8] = new Image();
pics[8].src = '../../knex/ballmachines/crazy/pics/crazy_top.jpg';
pics[8].addEventListener('load',pic9,false);
}
function pic9 () {};
-
Jacobly helped me out with that array pic stuff, thanks!
And can you open a link in a new tab via javascript?
-
http://stackoverflow.com/questions/4907843/open-url-in-new-tab-using-javascript
http://stackoverflow.com/questions/427479/programmatically-open-new-pages-on-tabs
You should always use google to check for answers to your questions before you post. Not only are you more likely to get your answer faster and thus implement it faster but you also keep others from having to use google ;)
-
*necrobump*
I have a very wired bug, i have the following php code:
<?php
error_reporting(0);
//ini_set('display_errors', '1');
session_start();
$_SESSION['player']=1;
$_SESSION['game']=1;
$_SESSION['id']=1;
$verbindung = mysql_connect("localhost","sorunome",<passwd>);
mysql_select_db("risk");
if ($_GET['action']=="lines") {
/*
$num = mysql_real_escape_string($_GET['num']);
$offset = mysql_real_escape_string($_GET['offset']);
$loop = true;
$counter = 0;
$doSleep = true;
if (max(mysql_fetch_array(mysql_query("SELECT MAX(id) FROM risk")))>=$num)
$doSleep = false;
$num = $num-$offset;
if ($_SESSION['id']!==NULL) {
while ($loop) {
if ($doSleep)
sleep(1);
$result = mysql_fetch_array(mysql_query("SELECT * FROM risk WHERE id='1'",$verbindung));//".($num+$counter)."
die(mysql_error());
if ($result) {
if ($result["player"]==$_SESSION['player'] || $result["game"]==$_SESSION['game'] || $result["player"]=="0") {
echo $result["content"]."\n";
$counter++;
} else
$counter++;
if ($counter>$offset)
$loop = false;
}
}
echo "nextLine(\"".($num+$offset+1)."\",0);";
} else
echo "lostConnection();";
*/
}
if ($_GET['action']=="send") {
$request = $_GET['request'];
if ($request=="MAP") {
mysql_query("INSERT INTO riskserver (player,game,content) VALUES ('".$_SESSION['player']."','".$_SESSION['game']."','MAP');",$verbindung)or die(mysql_error());
}
}
?>
And no matter how i call it I get 504 gateway timeout, yes, that big block IS commented out.
-
Your error isn't probably related to your php code, as it's a gateway error. Do you have a gateway? Is it timeouting? Do your script takes too long to execute?
-
I have a timeout - 1 minuet, and somehow it takes longer than that, or i don't know what you mean >.<
EDIT: WUT?!?!?! somehow php files load infinity, without php it is working, but it worked earlier today D:/me needs to bug albertro
-
The only thing I see is that your mysql server has a problem.
-
EDIT: WUT?!?!?! somehow php files load infinity, without php it is working, but it worked earlier today D:/me needs to bug albertro
-
Yeah, Albert should be able to fix it.
-
He's also the one who set it up, LOL >.<
-
Ok, the result is now: php crached.
Why did it crach? My server has not enough RAM D: