jquery ajax prompt aborted by user

Some old application that working good in IE8. But in Firefox application tab/window simply closed.  "PROMPT ABORTED BY USER"  exception appears in Firebug console.

I have some page that have <button> on it that run ajax request. I expect that some content will be added to page as response to ajax. But in real window simply closed. 

As usual problem was solved with help of Stackoverflow.

AJAX POST handler causing “uncaught exception” 

gave me a hint.  It has the similar problem and solution is to make form onsubmit="return false;". 

So i understood that unexpected submit happens when i run ajax request.

So the problem is : Firefox and Chrome use default type="submit" for <button> tag, but IE type="button". This causes different behavior.

Solution: explicitly specify type="button".

How to change remote_addr header programmatically

I looked for the way to change REMOTE_ADDR header using HtmlUnit, or HttpClient. After some attempts realized that this is impossible. It is still possible on the level of socket programming but not http.

Because REMOTE_ADDR is not http request header. And even if somebody will success to send to server request with changed IP (REMOTE_ADDR) how she expects to get response?

Below the (PHP) code that prints out all of the request headers.

<html>

<body>

<ol>

<?php

   foreach($_SERVER as $h=>$v)

     if(ereg('(.+)',$h,$hp))

       echo "<li>$h = $v</li>\n";

   header('Content-type: text/html');

  ?>

</ol>

</body>

</html>

And this is (slightly censored) the result:

  1. DOCUMENT_ROOT = /home5/sdfsdfsdf/public_html
  2. GATEWAY_INTERFACE = CGI/1.1
  3. HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  4. HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7
  5. HTTP_ACCEPT_ENCODING = gzip,deflate
  6. HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5
  7. HTTP_CONNECTION = keep-alive
  8. HTTP_COOKIE = __utma=47503804.842271267.1313228251.1313825844.1313950009.3
  9. HTTP_HOST = sdfsdfsdf.com
  10. HTTP_KEEP_ALIVE = 115
  11. HTTP_USER_AGENT = Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.28) Gecko/20120306 Firefox/3.6.28 GTB7.1
  12. PATH = /bin:/usr/bin
  13. QUERY_STRING =
  14. REDIRECT_STATUS = 200
  15. REMOTE_ADDR = 183.89.1.50
  16. REMOTE_PORT = 10136
  17. REQUEST_METHOD = GET
  18. REQUEST_URI = /test/print_headers.php
  19. SCRIPT_FILENAME = /sdfs/javaghsdfsdfsdfos/public_html/test/print_headers.php
  20. SCRIPT_NAME = /test/print_headers.php
  21. SERVER_ADDR = 66.147.242.173
  22. SERVER_ADMIN = webmaster@sdfsdfsdf.com
  23. SERVER_NAME = sdfdsfsdf.com
  24. SERVER_PORT = 80
  25. SERVER_PROTOCOL = HTTP/1.1
  26. SERVER_SIGNATURE = Apache Server at javaghost.com Port 80
  27. SERVER_SOFTWARE = Apache
  28. W3TC_ENC = _gzip
  29. file_gzip = /ramdisk/cpud/status
  30. PHP_SELF = /test/print_headers.php
  31. REQUEST_TIME = 1337838235
  32. argv = Array
  33. argc = 0 183.89.1.50

Firefox function location() conflict

When working on adjustment some old IE8 project to Firefox, found curious problem : some page not opened (blank screen) and function location() {… written to address field.

Cause that page have defined function with name location.

Workaround is obvious: just rename function to location1, for example.

I don’t want to go deep inside to find exact cause. More likely that Firefox have window.location property implemented as function location(). And two location() functions get in conflict.

Incorrect result using ROUND_HALF_UP fixed

BigDecimal.ROUND_HALF_UP widely used in Java to compute and display currency values.

Let look on next example.

We have some price: $1498.00 (doesn’t matter what it is). And some fee (also doesn’t matter who get it) that counted by formula : 

          fee = price * 0.075 + 0.99

so, we have next java code

double fee = (Double.parseDouble("1498") * 0.0775 ) + 0.99;

BigDecimal feeRounded = new BigDecimal(fee).setScale(2, BigDecimal.ROUND_HALF_UP);

and we expect result in feeRounded: 117.09 because fee = 117.085  . And for another prices all properly works : we get exactly what we expect to get.

But we get 117.08   !!  Why?

Because new BigDecimal(fee) is not equal 117.085  .

It equals 117.08499999999999999937422392… and so on. And rounded to 117.08 .

To work properly code must be changed to create BigDecimal from String not from double.

double fee = (Double.parseDouble("1498") * 0.0775) + 0.99;

BigDecimal feeRounded = new BigDecimal(fee + "").setScale(2, BigDecimal.ROUND_HALF_UP);

Uncaught TypeError: object is not a function solved

When button clicked nothing happens. But must, because have onclick attribute with call to some JavaScript function.

When open firebug realized that error "Uncaught TypeError: object is not a function" occurred.

Cause that my html page has element with id attribute value equals to function name that tried to call. For example function showAlert() and button with id="showAlert".

Solution obvious : just change  id to "showAlertButton".

How to close SWT application to system tray?

I wrote java application that once configured starting to perform long time task and may stay without user interaction days, weeks, months, years.

For this kind of applications (good example mTorrent) very important to be possible close application window but keep application working and have possibility to open application from systray icon.

There are two code snippets below.

First creates systray icon with menu that have two menu items: "Open" and "Exit".

private void createTray() {

        Tray tray;

        TrayItem item;

        Image image;

        tray = display.getSystemTray();

        if (tray == null) {

            System.out.println("The system tray is not available");

        } else {

            item = new TrayItem(tray, SWT.NONE);

            item.setToolTipText("Wp Commenter");

            item.addListener(SWT.Show, new Listener() {

                public void handleEvent(Event event) {

                    System.out.println("show");

                }

            });

            item.addListener(SWT.Hide, new Listener() {

                public void handleEvent(Event event) {

                    System.out.println("hide");

                }

            });

            item.addListener(SWT.Selection, new Listener() {

                public void handleEvent(Event event) {

                    System.out.println("selection");

                }

            });

            item.addListener(SWT.DefaultSelection, new Listener() {

                public void handleEvent(Event event) {

                    System.out.println("default selection");

                }

            });

            final Menu menu = new Menu(shell, SWT.POP_UP);

 

            MenuItem openMenuItem = new MenuItem(menu, SWT.PUSH);

            openMenuItem.setText("Open");

            openMenuItem.addListener(SWT.Selection, new Listener() {

                public void handleEvent(Event event) {

                    shell.setVisible(true);

                    shell.setMaximized(true);

                }

            });

            MenuItem exitMenuItem = new MenuItem(menu, SWT.PUSH);

            exitMenuItem.setText("Exit");

            exitMenuItem.addListener(SWT.Selection, new Listener() {

                public void handleEvent(Event event) {

                    System.exit(0);

                }

            });

 

            item.addListener(SWT.MenuDetect, new Listener() {

                public void handleEvent(Event event) {

                    menu.setVisible(true);

                }

            });

 

            // image = SWTResourceManager.getImage(MakeBreak.class, "Backup-Green-Button-icon.png");

            image = SWTResourceManager.getImage(WpCommenter.class, "images/mb4.png");

            item.setImage(image);

        }

 

    }

Second adds listener to shell that "hide" application behind systray icon on "Closed" event.

shell.addShellListener(new ShellListener() {

            public void shellActivated(ShellEvent event) {

            }

 

            public void shellClosed(ShellEvent event) {

                event.doit = false;  //!! for this code i looked long time

                shell.setVisible(false);

            }

 

            public void shellDeactivated(ShellEvent event) {

            }

 

            public void shellDeiconified(ShellEvent event) {

            }

 

            public void shellIconified(ShellEvent event) {

                //shell.setVisible(false);

            }

        });

Sex and web design relationship

 

I hope this blog will not be penalized by Google for word sex. So how sex and web design are related? You will not believe. Directly.

Do You wonder why so many sites (including this one) have orange buttons and links? No? Curiosity kills the cat? I will say you anyway.

Orange stimulus sexual organs. That is.

Anytime you see orange button, know, web master drives your action based on your sexuality. This is wonderful.

How to create web site for free?

 

Main expense for maintaining web site is the hosting.  "Unlimited" shared web hosting can costs from $50 up to $150  in a year depends on provider.

And in case your sites became very popular some limitations will appear.

Hosting sites on paid hosting have its pros: different types of application can be hosted with 1 click installation, some providers have drag and drop site builders, and so on and so on. And most important on paid hosting we can use WordPress.

But if it worth in case we need 5 page business site or blog?

There is only one really unlimited hosting. It provided by Google and called Blogger. We can host unlimited sites. And in case site became very popular will not be need for dedicated server costing $150 each month.

Google can provide really unlimited hosting and does it for free. It has its own interest but this is another story.

Create site with Blogger is very simple.

1. Go to blogger.com and create blog.

2. Go to <Posting> tab and create all pages exclude Home page using <Edit pages>.

3. Create static Home page.

The last  is a tricky one. Read "How to create static home page for Blogger based web site".

Sometimes we want our blogger based site to display static  (permanent, fixed) content on front page. By default blogger displays several last posts.

There are two options:

  1. Create static home page using regular post.
  2. Create static home page using Text widget.

 

First option can be very simple.

  1. Create post (Posting –> New Post) that we want to display on home page.
  2. Go to Design –> Page Elements -> Blog Posts widget –> Edit. Number of posts on main page enter 1. Uncheck all options below. Save.
  3. Go to Settings –> Archiving. Choose “No” for Enable post pages. Save.

In most cases that is all.

Possible problem that our loved template hardcoded to display only excerpt (summary) of post on front page. In this case we need to edit template manually. We do not fear.

  1. Go to Design –> Edit HTML. Look for code like:
       1: <div class='post-body entry-content'>

       2: <b:if cond='data:blog.pageType != &quot;item&quot;'>

       3: <b:if cond='data:blog.pageType != &quot;static_page&quot;'>

       4: <div expr:id='&quot;summary&quot; + data:post.id'><data:post.body/></div>

       5: <script type='text/javascript'>createSummaryAndThumb(&quot;summary<data:post.id/>&quot;);</script>

       6: </b:if></b:if>

       7: <b:if cond='data:blog.pageType == &quot;item&quot;'>

       8: <data:post.body/></b:if>

       9: <b:if cond='data:blog.pageType == &quot;static_page&quot;'><data:post.body/>

      10: </b:if>

      11: <div style='clear: both;'/> <!-- clear for photos floats -->

      12: </div>

  2.   Change it to

   1: <div class='post-body entry-content'>

   2: <data:post.body/>

   3: <div style='clear: both;'/> <!-- clear for photos floats -->

   4: </div>

 

(Code in another theme can be slightly different.) Voila. Done.

Option two. Create static home page with Text widget.

1. Go to Design – > Page elements –> Blog posts widget –> Edit. Enter number of posts =0.

2. Click Ad widget and choose Text. Enter content you want to display. Title leave blank.

3. Place Text widget just before or after Blog posts.

4. Tricky one: make Text widget to be displayed only on home page.

  •     Go to Design –> Edit HTML. Look for code like:
   1: <b:widget id='Text1' locked='false' title='' type='Text'>

   2: <b:includable id='main'>

   3:   <!-- only display title if it's non-empty -->

   5:   <b:if cond='data:title != &quot;&quot;'>

   6:     <h2 class='title'><data:title/></h2>

   7:   </b:if>

   8:   <div class='widget-content'>

   9:     <data:content/>

  10:   </div>

  12:   <b:include name='quickedit'/>

  13: </b:includable>

  14:  

  15: </b:widget>

  •     change it (add conditional statement) to:
   1: <b:widget id='Text1' locked='false' title='' type='Text'>

   2: <b:includable id='main'>


   4:   <b:if cond='data:blog.url == data:blog.homepageUrl'>

   5:   <b:if cond='data:title != &quot;&quot;'>

   6:     <h2 class='title'><data:title/></h2>

   7:   </b:if>

   8:   <div class='widget-content'>

   9:     <data:content/>

  10:   </div>

  11:   </b:if>

  12:   <b:include name='quickedit'/>

  13: </b:includable>

  14:  

  15: </b:widget>

We just added conditional statement around widget content:

<b:if cond=’data:blog.url == data:blog.homepageUrl’>

     …. widget content…

</b:if>

 

Summary. The first way (with regular post) seems to be more simple. In most cases it is not required code editing. Example of site with static home page with regular post. But in some cases  second technique with Text widget can be useful too.

 

Dynamic Views is a new Blogger template that used by half million of blog owners.

I tried to use it but realize that it hardly customizable and more of this : Pages widget that used for creating navigation bar, not displayed at all in Opera and Safari.

All these mobile funs with iphones and ipads will not see these sites properly.

Workaround very painful – just not use this template. Painful because template looked very good.

How to increase Alexa Rank quickly?

 

Alexa Rank is a rank provided by alexa.com site run by Amazon.

Though claimed to be inaccurate, Alexa Rank give possibility to quickly value any site traffic range.

Alexa uses browsers toolbars (plugins, extensions) and site widgets to get information about site visitors.

So, in order to increase Alexa Rank we do:

  1. Install alexa plugins to all browsers.
  2. Install alexa widgets to all sites.

 

Good Luck!

Best [free] wordpress theme ever? Flexibility

Best free  theme for WordPress is the Flexibility 3.

Especially for web master that manages many blogs.

This theme allows to create unique design in several mouse click without knowing of any html/css.

Has support for AdSense and Google Analytics.

What is the most trusted web hosting provider?

The biggest webhosting provider is GoDaddy. The second is 1&1. But percent of high trafficated domains that they host relatively low.

The highest rate of high trafficated domains has HostGator. Also HostGator famous for its great support.

What is the biggest web hosting provider?

 

GoDaddy. It hosts more domains than all other providers together.

Google map is not displaying in WordPress

 

That is. I tried to insert Google Map into wordpress post using several google maps and iframe plugins and without result. All that i got is a proper code in the resulting html but map is not displayed.

Solution is very simple as usual for this kind of stupid problems: i just inserted embed code from Google Map page  to post editor in html mode. Voila.  


View Larger Map

Chrome is not showing frame border

 

I have frameset with

   1: frameborder="yes"

attribute.  It works well in IE and FF (showing borders between frames) but not in Chrome.

 

Workaround very simple  — just delete attribute completely. Now it working in all browsers.

onfocus not working in Chrome

That is. I am just trying to adjust some old project, working fine only in IE8, to Firefox and Chrome.

 

Workaround very simple  –  change onfocus to onclick.

click() not working in Chrome

 

I have code like

   1: var link = document.getElementById("myLink");

   2: link.click();

and it is working in all browsers (really tested in IE8 and FF9) but not in Chrome.

 

Stackoverflow has three questions about this issue without workaround.

http://stackoverflow.com/questions/5015893/onclick-parent-getelementbyid-click-not-working-in-chrome

http://stackoverflow.com/questions/1938356/chrome-browser-action-click-not-working

http://stackoverflow.com/questions/7857289/click-not-working-in-chrome

People speak about some security limits.

And voila – solution:

   1: var link = document.getElementById("myLink"); //existing code

   2: $(link).click();

or pure jQuery style:

   1: $("#myLink").click();

jQuery rules!!

How to close parent window in Firefox and Chrome

.. and possible also in Opera, Safari etc.

The problem:

   1: parent.window.close();

that working well in IE8 but not working in Firefox and Chrome. Some state that for security reasons.

Solution (lol):

   1: top.window.close();

 

A little more details:

I have a page that opens popup using showModalDialog(….) function.

Inside popup i have a frameset(old project) with two frames. One of them have button which onclick="parent.window.close()" not working in FF but onclick="top.window.close()" successfully closes popup.

 

If You american citizen do something with SOPA because it can be "ZHOPA".

Good Luck!

I have some code that works correct when run from Eclipse, but throws FileNotFoundException when run from jar.

Even more this code properly worked before but stopped after… I don’t know. May be after some Windows update?

Here is the code

 

   1: String path = Thread.currentThread().getContextClassLoader().getResource("stopwords.txt").getPath();

   2: System.out.println(path);

   3: BufferedReader input = new BufferedReader(new FileReader(new File(filePath)));

Output: file:/F:/PROMOTION/executor.jar!/stopwords.txt  — correct path to file, so file is found by getResource(…) method.

Exception thrown from code line 3:

java.io.FileNotFoundException: file:\F:\PROMOTION\executor.jar!\stopwords.txt (The filename, directory name, or volume label syntax is incorrect)

What cause for this strange behavior  I don’t know. Stackoverflow has about 4 questions about same issue, but not explain cause as well.

But workaround (at least in my case) the next: to use getResourceAsStream() instead of getResource().getPath() and Scanner instead of BufferedReader.

Full working code is looks like:

   1: InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("stopwords.txt");

   2: List<String> lines = new ArrayList<String>();

   3:          Scanner scanner = new Scanner(stream);

   4:             try {

   5:               while (scanner.hasNextLine()){

   6:                 lines.add(scanner.nextLine());

   7:               }

   8:             }

   9:             finally{

  10:               scanner.close();

  11:             }

 Page 1 of 7  1  2  3  4  5 » ...  Last »