Jump to content

nogray

Members
  • Posts

    930
  • Joined

  • Last visited

Posts posted by nogray

  1. tables, tr, td can't have focus since the user doens't interact with them directly. Depending on what are you trying to do with the focus event, there is another approach.

     

    You can add an anchor tag inside your td and once that anchor tag receive focus, you would simulate a focus on the td visually. Here is a quick sample.

    <input type="text" value="tab out of here" />
    <table id="my_table" style="cursor:pointer;" onclick="do_focus(); do_click(); document.getElementById('my_anchor').focus();">
    <tr>
        	<td>
            	<a href="#" id="my_anchor" onclick="do_click(); return false;" onfocus="do_focus();" onblur="do_blur();"></a>
                This is some text
            </td>
        </tr>
    </table>
    <input type="text" value="tab out of here" />
    <script type="text/javascript">
    function do_click(){
    	alert('clicked');
    };
    
    function do_focus(){
    	document.getElementById('my_table').style.background = "#336699";
    	document.getElementById('my_table').style.color = "#ffffff";
    	document.getElementById('my_table').style.border = "dotted 1px #000000";
    };
    
    function do_blur(){
    	document.getElementById('my_table').style.background = "#ffffff";
    	document.getElementById('my_table').style.color = "#000000";
    	document.getElementById('my_table').style.border = "0px";
    };
    
    </script>
    

  2. This might not be a loading problem, but an execution time problem. The browser might load the JS file and continue on the page and load the next file, but there might be a delay in executing the first file and the second file start executing which causes the error. This can happen specilly if you are loading locally or from cache.

     

    To avoid this problem, make sure all your functions are in the ready function or add a defer="defer" to your additional script tags (after the jq).

  3. whenever you alter the innerHTML of an object, the browser will reset the entier object html (and you would lose and dom refrence as well). You should add the tr, td using document.createElement(tag) and object.appendChild(child)

     

     

  4. .hta is an HTML application and need to run on a desktop (not on a server). I tested on IE 9 as an html file on my desktop, I did something similar long time ago with IE7.

     

    There are a few zones for IE, make sure activex is allowed on your security zone (either local intranet or internet). ActiveX is not recommended for browsing the internet in general.

     

    .hta files is an HTML file that runs like a desktop application without any security restrictions.

     

    If you need this to run as a server app, you might have to add the your site (or localhost) to the trusted sites security zone and allow activex to run on trusted sites. Also, make sure the file bath is correct and accessible from your page.

  5. First your editable content area should be iframed to avoid security issues and conflicts. I assume you have an "Edit HTML" button, whenever the user change the HTML code, you would need to scan it for any scripts (including events) or flash objects and remove them.

  6. Technically, you cannot print directly using javascript without user interaction. The reason your script doesn't work is because the print dialog will block any script exection until the user either clicked yes or no.

     

    However, you can run around this issue by creating a text file and opening in with a print command. The sample code below will only print the text of your page (will get the innerText of your print div).

    <div id="my_print_div">
    <strong>This is a test</strong><br /><br />Hello World
    </div>
    <script type="text/javascript">
    // the text file name (same as the html file + .txt)
    var txt_file = "C:\\Users\\Desktop\\test.txt";   // you will have to change this, use double \
    
    // creating a file and printing it
    function create_file(){
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var f = fso.CreateTextFile(txt_file, true);
    f.WriteLine(document.getElementById('my_print_div').innerText);
    f.Close();
    print_file();
    };
    
    function print_file(){
    var shell = new ActiveXObject("WScript.Shell");
    shell.Run("notepad.exe /p "+txt_file);
    };
    
    create_file();
    
    </script>
    

     

    Notes: Use a <br /> for line breaks and the output is only text. Use double \ in the file path to avoid wrong path issues.

     

    If you can get the printable content in a RTF format (for text format), you can replace the .txt in the file name to .rtf and change NotePad.exe to wordpad.exe

  7. To set the height in CSS to a percentage, you would need to set the height of all the parent elements including the html document. Otherwise, the browser doesn't have a refernace for the percentage. Last is to add overflow:auto to the content div.

    e.g.

    html, body {height: 100%}
    

    This might not work the same in all browsers, not tested

     

  8. You would need to add a value="" to the Select a Category and add an ID to the select menu

    <select name="dropdown" id="dropdown"><option selected="selected" value="">Select A Category</option>

    and test for value == ""

    // I don't use jQuery
    if (document.getElementById('dropdown').value == "") {
    // do something
    }
    

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.