...

Hi! I’m Starx

experienced Software Developer. And this is my blog
Start Reading About me
Blog Page
March 18, 2012

background image not appear in IE but appears in firefox

Question by Brendan Fernandes

my background images appear in chrome and firefox, but not in IE 8.
my site is www.burodsin.com the first homepage with the logo.

in css background, i added

.bclass:link {
background-image: url('images/buroimagenew.jpg');
position: absolute;
width: 40px;
height: 97px;
display: block;
z-index:12;
 }

Answer by Starx

The problem on your page is that you are defining repeat properties no-repeat on background-image, like this

background-image: url('images/buroimagenew.jpg') no-repeat; 
                                                /* ^ This is NOT a background-image accepted value */

Either separate the properties like

background-image: url('images/buroimagenew.jpg'); 
background-repeat: no-repeat;

Or write the correct shorthand rule.

background: url('images/buroimagenew.jpg') no-repeat; 
Read more

Multiple css files or one big css file?

Question by Alex90

Which one is better and faster? why?

using only one file for styling:

css/style.css

or

using several files for styling:

css/header.css
css/contact.css
css/footer.css
css/tooltip.css

The reason Im asking it is that im developing a site for users who have very low internet speed. country uganda. So I want to make it as fast as possible.

Answer by hustlerinc

Using a single file is faster because it requires less HTTP requests (assuming the amount of styles loaded is still the same).

So it’s better to keep it in just one file.
Separating CSS should only be done if you want to keep for example IE specific classes separate.

Answer by Starx

As per Yahoo’s Performance Rules [source], It is VERY IMPORTANT to minimize HTTP requests

From the source

Combined files are a way to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining
all CSS into a single stylesheet. Combining files is more challenging
when the scripts and stylesheets vary from page to page, but making
this part of your release process improves response times.

It is quite uneasy to develop using combined files, so stick to developing with multiple files but you should combine the files once you are deploying the system on the web.

I really recommend using boilerplate’s ant build script. You can find it here.

It Combines and minifies CSS

Read more

Prevent HTML5 video from being downloaded (right-click saved)?

Question by python

How can I disable the “Save Video As…” from the right-click menu to prevent from clients from downloading the video?

And, are there is more complete solutions that prevent the client from accessing the file path directly?

Thanks

Answer by Joseph the Dreamer

In reality, you can’t. But you can make it harder to steal.

In my experience grabbing videos, I just use the debugger of the browser. I prepare the network tab and let the video load. Then I look for it in the loaded resources, grab it’s url, and open it in another tab to download it.

the routine was basically:

  • load the video
  • get the link
  • load it again but this time, not using the player

One thing you can do to prevent this method is to prevent the link from being reusable. Once the player loads using the disposable url, the server makes it unusable.

Similar to CSRF prevention, create a token and store it in the session. At the same time, place this token in a hidden input tag, cookie, or in the video link itself when generating the page. Then when the player loads, have it request for a access of the video using the token. If the token sent exists in the session, the server allow access to video. After access is allowed, delete that token from the server-side so that further use of the same token will be invalid.

To add to that, have the token expire on the server after several minutes of being unused, enough time for the page to use it for the video request but short enough for one to get the link and use it.

This method will NOT prevent:

  • Tools that pick up the file from the cache. Streamed videos (especially those done streaming) are stored in the cache of the browser.
  • This will not prevent tools that intercept the player’s video request. Some tools hijack the request that uses the token to gain access.

After scouring the net about customizing the context menu of an html5 video, i found this article. it mentions about having the video be overlayed by a div to prevent direct click on it (thus no right-click to the video). as for the controls, i believe one can build your own video controls in JS so that it is outside of the video (so that you can overlay the div in front of the video without covering the controls).

Answer by Starx

Simple answer,

YOU CANT

If they are watching your video, they have it already

You can slow them down but can’t stop them.

Read more

How do I add text inside of an input field using jQuery?

Question by John Anderson

This should be easy, but nothing seems to work. I have a jQuery function that contains two parameters. The first parameter (pageID) is supposed to be inserted into a hidden field. It works correctly. I want the second parameter to be inserted into an html input field. That is, I want to see the contents of the parameter ‘pageName’ inside the form field as if I had just typed it in myself. Here is the code:

function insertIntoHiddenField(pageID,pageName)
{
    $('input[name=page_id]').val(pageID);
    $('input[name=page_name]').val(pageName);
}

When I look at the source code, I find that the value attribute in the input tag contains the value from the parameter ‘pageName’. But, the input field itself is empty. I want to see that value in the input field. What am I doing wrong?

By the way, I also tried (without success) the following:

$('input[name=page_name]').text(pageName);
$('input[name=page_name]').innerhtml(pageName);
$('input[name=page_name]').append(pageName);

Answer by Starx

Give an id to the hidden element. Just to be on the safe side and use .val()

$('#page_name').val('newtext');
$('#page_id').val('newtext');

Demo

However, your method works perfectly for me. Check here

Read more

How to load the db class after the session in CodeIgniter

Question by yeah its me

when i want to make a foreach($_SESSION[‘banners’]->result() as $banner), i get this error:

The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CI_DB_mysql_result" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in….

how can i load the db class after the session, i am using the native session $_SESSION, i dont want to use the codeigniter sessions because they have problems in IE, how can i resolve this problem?? or what function i need to use to load the DB class after the session in CI?

Answer by Starx

Use the native Codeigniter Session, to avoid such problems. To fix the problem with IE, make the following changes on config.php

$config['sess_cookie_name']        = 'ci_session'; 

to

$config['sess_cookie_name']        = 'cisession';

  • Initiate the library like this $this->load->library('session');

  • Set data in the session like this $this->session->set_userdata('item', 'value');

  • And read the values like $this->session->userdata('item');

Then on your application you will able to use it like this

foreach($this->session->userdata('banners') ->result() as $banner) {}
Read more

i want to get data from textbox in php

Question by vishal5721

I hav created a group of textboxes using a loop and its names are unique and names are assigned using variable ( like ). Then How can i retrieve the values in that textboxes after a button click with in a loop. Really I cant move from here. Can anyone plz help me..
Part of the my code is given below

$q1="select * from result where s_id=$sid";
$res1=mysql_query($q1,$link) or die($q1);
echo '<form action="editresultprofile.php?sid=$sid">';
while($row1=mysql_fetch_assoc($res1))
    {
    echo '<td><input type="text" name='.$row1['sub_name'].' class="textfield" value='.$row1['result'].'></td>';
    }
    echo '<input type="submit" value="update" ></form>';

Answer by Starx

It is not possible through PHP. You have use javascript to get the values in the textbox at realtime.

But using php, you have submit the form first, and then only you will get the data on the page its submit the data too. For example as per your question, only editresultprofile.php will be able to get the data values.

On editresultprofile.php, you can do

$name = $_POST['thesubname']; //You have to change the name to what is reflected on your case

However, if you use javascript, you can get the values as they were typed, before submitting the form.

function getValues(){
  var tbox = document.getElementById('yourtextboxid');
  alert(tbox.value);
  return false; //stop the submisison
}

Attach the function in the onSubmit event of the form.

<form onsubmit="return getValues()" >
Read more

Jquery keyup multiple inputs

Question by Claremont

I am trying to make it so when someone uses the input the text that corresponds to it will show.

<div class="content1" style="display: block;">Content 1</div>
<div class="content2" style="display: none;">Content 2</div>
<div class="content3" style="display: none;">Content 3</div>
<div class="content4" style="display: none;">Content 4</div>

<ul class="addReview">
        <li><p>Input 1</p><input type="text" name="input1" value="" id="input1" autocomplete="off" maxlength="2"  /></li>
        <li><p>Input 2</p><input type="text" name="input2" value="" id="input2" autocomplete="off" maxlength="2"  /></li>
        <li><p>Input 3</p><input type="text" name="input3" value="" id="input3" autocomplete="off" maxlength="2"  /></li>
        <li><p>Input 4</p><input type="text" name="input4" value="" id="input4" autocomplete="off" maxlength="2"  /></li>
    </ul>

Would I do a keyup function for each input or is there a way to make one keyup function?

Answer by nnnnnn

This should do it for your current markup:

$('.addReview input[type="text"]').keyup(function() {
   $('div[class^="content"]').hide();
   $('div.' + this.id.replace(/input/, "content")).show();
});​

Demo: http://jsfiddle.net/WD3CU/

But it would be neater if you gave the divs a common class and different ids. E.g., if all the divs had a class “content” and an id in the form “content1” then you could do this:

$('.addReview input[type="text"]').keyup(function() {
   $('div.content').hide();
   $('#' + this.id.replace(/input/, "content")).show();
});​

Which looks similar but is much more robust (the way I did it for your current html will likely break if you were to give the divs additional classes).

Demo incorporating my suggested markup changes: http://jsfiddle.net/WD3CU/1/

Also, in my opinion it would make more sense to use the .focus() event rather than .keyup(), so that the appropriate div is shown as soon as the user clicks or tabs into one of the inputs.

Answer by Starx

You have to bind to a common selector like this

$('.addReview input:text').keyup(function() { });

demo

Or a class selector like this

$('.addReview .mytextboxclass').keyup(function() { });

demo

Or an attribute selector like in nnnnnn’s answer

$('.addReview input[type="text"]').keyup(function() { });​

demo

Read more

php array and mysql syntax error

Question by Andras Sebestyen

I am trying SwiftMailer to fetch the email addresses to an array() I have the original example and I know what I want to put in it but I can’t see the forest from the trees… any one out there with proper eyes please:

// Send the message
$result = $mailer->send($message);

// Send the message
$failedRecipients = array();
$numSent = 0;

Here is where I am struggling:

 foreach($groups as $value)
    { 
             echo "<h3>".$value."</h3>"; //this is working

    // get the email groups
    $sql="SELECT * FROM emails WHERE sendesstat=1 AND deleted=0 AND classhoz="".$value.""";
    $query=mysql_query($sql);

    // fetch the emails from the group
    while($data=mysql_fetch_array($query))
                {
                  $emil="'".$data["email"]."' => '".$data["firstname"]." ".$data["surname"]."'";
                  echo $emil;

this echo is working but I can’t put in the $to[] array… (sorry) and this is how it should appear:

$to = array('receiver@domain.org', 'other@domain.org' => 'A name');

the issue is the given name => 'A name' I am being sick and I can’t find the syntax !!!

                  $to[ ]= $emil;            
                }
    }

foreach ($to as $address => $name)
{
  if (is_int($address)) {
   $message->setTo($name);
  } else {
   $message->setTo(array($address => $name));
}

 $numSent += $mailer->send($message, $failedRecipients);
}

printf("Sent %d messagesn", $numSent);

please please everything else is working now only this bit is missing. Thank you

Answer by Starx

You are defining the $to array the wrong way.

Use this to add an item on the array

$to[$data["email"]] = $data["firstname"]." ".$data["surname"];
//  ^ Index           ^ Value

Later On, when you use foreach loop it will well differentiated into $address and $name, just the way you are doing.

foreach ($to as $address => $name) {
    echo $address;
    echo $name; 
}
Read more
March 17, 2012

jQuery animate() callback not working right with removeClass()

Question by Antonio Vitor

Hey guys I’m working on a jQuery code snippet that’s suppose to remove a class from an object after the animation has been completed. This is what I have so far:

$('.box').hover(function() {
        $(this).stop().addClass('active').animate({ 'margin-top': '-49px' }, 500);
    }, function() {
        $element = $(this);
        $(this).stop().animate({ 'margin-top': '0' }, 500, function() {
            $element.removeClass('active');
        });
    });

The problem is that sometimes when the animation completes the class is not removed. This happens when I move too fast between divs.

You can view an example here in the slider section there are three boxes inside the slider that says ‘City’, ‘House’, and ‘Business’.

Any help is appreciated.

PS the same thing happens on the main navigation, sometimes the sub-nav just hangs there. Here is the code for the navigation:

$('#navigation ul li').hover(function(){
        $("a:eq(0)", this).addClass("hover");
        $(this).find('ul:eq(0)').stop(true, true).slideToggle();
        }, function(){
            $("a:eq(0)", this).removeClass("hover");
            $(this).find('ul:eq(0)').stop(true, true).slideToggle();
        }
    );

Answer by Starx

Change your $element declaration to this

var $element = $(this);
Read more

Site directory Organizing

Question by user1275456

hi i want to know is there any way to sort folders in website as i want them to be,

i want to sort these in dreamweaver and also on server.
right now my website is not live as it is in development process and it will go live on completion,

also want to tell that majority of my pages are going yo be static.

i know to place a folder on top i can add underscore as prefix but i dont want underscore to display in url so i cannot use it.

is there any way to sort folders manually

Answer by Starx

This totally depends on the developer and his point of view. Do what makes it comfortable to manage and organise the files.

Read more
...

Please fill the form - I will response as fast as I can!