Skip to main content

Posts

Showing posts with the label html

PHP: Truncate HTML, ignoring tags

I want to truncate some text (loaded from a database or text file), but it contains HTML so as a result the tags are included and less text will be returned. This can then result in tags not being closed, or being partially closed (so Tidy may not work properly and there is still less content). How can I truncate based on the text (and probably stopping when you get to a table as that could cause more complex issues). substr("Hello, my <strong>name</strong> is <em>Sam</em>. I&acute;m a web developer.",0,26)."..." Would result in: Hello, my <strong>name</st... What I would want is: Hello, my <strong>name</strong> is <em>Sam</em>. I&acute;m... How can I do this? While my question is for how to do it in PHP, it would be good to know how to do it in C#... either should be OK as I think I would be able to port the method over (unless it is a built in method). Also note that I have included an HT

problem in file upload

I have the following markup: <select multiple="multiple" id="targetFilesList" style="width:200px;height:110px;"> </select> <input type="button" value="Get" id="btnGet" /> and following javascript: $(function() { $('#btnGet').click(function() { var fileupload = $("<input type='file' name='filetoupload' style='visibility:hidden;'/>"); $('body').append(fileupload); fileupload[0].onchange = function() { $('#targetFilesList').append('<option >' + fileupload.val() + '</option>'); return false; } fileupload.click(); }); }); Scenario is that i have to upload multiple files and once user has chosen the file to be uploaded i have to show the file name to user.Then,on submitting the

Showing a demo of my CSS on any website

I have developed a small component which can be put in to any website. Now, I want to develop a code that could demonstrate how would my component look like on any website. So, the person would come to my page and put in his URL and then my code should embed my custom JS/CSS in to the downloaded HTML and display it. Something like this . Here, like the feedback tab, I want to show my component any where on that page. Source: Tips4all

I want to show list items as 2 or more columns (dynamic alignment)

I am able to do the list using float:left; like this But I would like to show it like this (as 2 or more columns) How can I do that? @sandeep gave good solution. Unfortunately does not work in IE(need ie7 and above). any help? Source: Tips4all

Why is using onClick() in HTML a bad practice?

I have heard many times that using JavaScript events, such as onClick() , in HTML is a bad practice, because it's not good for semantics. I would like to know what the downsides are and how to fix the following code? <a href="#" onclick="popup('/map/', 300, 300, 'map'); return false;">link</a> Source: Tips4all

jQuery Text to Link Script?

Does anyone know of a script that can select all text references to URLs and automatically replace them with anchor tags pointing to those locations? For example: http://www.google.com would automatically turn into <a href="http://www.google.com">http://www.google.com</a> Note: I am wanting this because I don't want to go through all my content and wrap them with anchor tags. Source: Tips4all

Passing parameters to a JQuery function

I'm creating HTML with a loop that has a column for Action. That column is a Hyperlink that when the user clicks calls a JavaScript function and passes the parameters... example: <a href="#" OnClick="DoAction(1,'Jose');" > Click </a> <a href="#" OnClick="DoAction(2,'Juan');" > Click </a> <a href="#" OnClick="DoAction(3,'Pedro');" > Click </a> ... <a href="#" OnClick="DoAction(n,'xxx');" > Click </a> I want that function to call an Ajax jQuery function with the correct parameters. Any help? Source: Tips4all

Is there any use of favicon.ico for mobile websites?

Is there any use of favicon.ico for mobile websites? will it be shown in browser address bar and tabs in mobile websites We use apple icons <link rel="apple-touch-icon" href="/apple-touch-icon.png"/> in mobile websites. what about Android, Blackberry and Windows 7 phone? Is favicon.ico useful for other mobile phones other then iOS mobiles Source: Tips4all

Best way to determine user"s locale within browser

I have a website (Flash) localized into a dozen of languages and I want to auto-define a default value depending on the user's browser settings in order to minimize the steps to access the content. FYI, I cannot use server-scripts due to proxy restrictions, so I guess JavaScript or ActionScript would be appropriate to solve the problem. Questions: What would be the best method to 'guess' the user's locale ? Are there any existing simple classes/functions that could help me out (no complex localization bundles) ? Specially to break down all the possible languages into a smaller number (the translations I have) on a smart way . To which point can I trust such a solution ? Any other workarounds or suggestions ? Thanks in advance! Source: Tips4all

Pass mouse events through absolutely-positioned element

I'm attempting to capture mouse events on an element with another absolutely-positioned element on top of it. Right now, events on the absolutely-positioned element hit it and bubble up to its parent, but I want it to be "transparent" to these mouse events and forward them on to whatever is behind it. How should I implement this? Click here for an example page . All its divs flash on mousedown. Source: Tips4all

Creating heatmaps using <canvas> element?

Are there any JavaScript libraries out there that allow you to create heatmaps using in-browser graphic rendering features such as <canvas> or SVG? I know about HeatMapAPI.com, but their heat maps are generated on the server side. I think that in the era of <canvas> element we don't need that anymore! If there is nothing like this yet, are there any volunteers to participate in creating such a tool? Source: Tips4all

Flash on top of jQuery dialog

I know many have asked this question, but I think my situation is a little bit different. I have a site where I have some ads which is Flash hidden in a because of xhtml/html compatibility issues. But the flash elements is on top of my jQuery dialogs which is not ideal. Some solutions have suggested setting wmode to opaque but I can't because my ads are scripts which outputs flash elements. Another solution suggested hiding ads when a dialog is shown. So my question is: Is there a way to put flash content behind my jQuery dialogs while they are visible and without altering the flash code? Best regards, Lasse Espeholt Update: I have now reopned the question with a bounty. As for now, I hide every Flash ad on "show dialog". But this is still not an optimal solution. So, I'm looking for a script which can make every Flash animation to opaque (a jQuery solution would be nicest, but a plain JavaScript solution will do). Or if there should be another solution n

jQuery: Move Table Row?

Say I had to links with up/down arrows for moving a table row up or down in order. What would be the most straightforward way to move that row up or down one position (using jQuery)? There doesn't seem to be any direct way to do this using jQuery's built in methods, and after selecting the row with jQuery, I haven't found a way to then move it. Also, in my case, making the rows draggable (which I have done with a plugin previously) isn't an option. Source: Tips4all

Loading NSData into a UIWebView

In my web browser, I am trying to load a UIWebView with NSData obtained from an NSURLConnection. When I try to load it into the UIWebView, instead of the site, it comes up with the HTML plain text. Here is my code: in viewDidLoad: NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.msn.com"]]; [NSURLConnection connectionWithRequest: request delegate:self]; later in the code: -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ webdata = [NSMutableData dataWithData: data]; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection{ [webview loadData:webdata MIMEType: @"text/html" textEncodingName: @"UTF-8" baseURL:nil]; }

JAVA: How can I download an HTML file from a site that requires cookies enabled?

I'm trying to download an HTML file from a site. I'm using the following simple method: URL url = new URL("here goes the link to the html file"); BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream())); String htmlfile = ""; String temp; while ((temp = br.readLine()) != null) { htmlfile+= temp; } The problem is that I get the following String in the htmlfile variable: The installation of ... requires the acceptance of a cookie by your browser software. The cookie is used to ensure that you and only you are able to access information .... In other words, I need to somewhat enable cookies when opening a stream from the url. Is it possible to achieve this by using URL or do I need a different method? Thanks in advance

Dynamic Dropdown Menu if-else does not become dynamic

I have two dropdown menus, im having trouble with making the options for the second dropwdown to be dependent on the choice on the first dropdown menu. $city=""; $formcontent =<<<EOT <label>Assumed Bitten City : </label> <select name="AssumedBittenCity" id="AssumedBittenCity"> <option value="0">Make a Selection</option> <option value="Caloocan City">Caloocan City</option> <option value="Las Pi&#241;as City">Las Pi&#241;as City</option> <option value="Makati City">Makati City</option> <option value="Malabon City">Malabon City</option> <option value="Mandaluyong City">Mandaulyong City</option>