Solved

Javascript in FireFox

Posted on 2006-11-03
7
784 Views
Last Modified: 2011-10-03
This issue is very annoying.  I have a javascript function on my web-site that works fine in Internet Explorer but does not work in FireFox.

Here's the idea behind the script:
 A user wants to view vendors in a different region - they click "Change Regions"
 A flash menu of the state pops up, allowing them to select the region they want.
 The Flash Page links to a page called KickBack.asp which submits a hidden form.
 The form processes and redirects the user to a different home page with their region.

Here's the code on the kickback.asp page:

<%
'From the Flash Pop Up Menu
the_region = Request("reg")

%>
<html>
<head>

<title>RegSend</title>
<script language="javascript">
      function changevalue(flag)
      {
            if (flag==1)
            {
                  window.opener.document.register.w_region.value="1";
                  window.opener.document.register.submit();
            }
            else if (flag==2)
            {
                  window.opener.document.register.w_region.value="2";
                  window.opener.document.register.submit();
            }
            else if (flag==3)
            {
                  window.opener.document.register.w_region.value="3";
                  window.opener.document.register.submit();
            }
            else if (flag==4)
            {
                  window.opener.document.register.w_region.value="4";
                  window.opener.document.register.submit();
            }
            else if (flag==5)
            {
                  window.opener.document.register.w_region.value="5";
                  window.opener.document.register.submit();
            }
            else if (flag==6)
            {
                  window.opener.document.register.w_region.value="6";
                  window.opener.document.register.submit();
            }
            else if (flag==7)
            {
                  window.opener.document.register.w_region.value="7";
                  window.opener.document.register.submit();
            }
      }
</script>
</heaD>


      <body onload="javascript:changevalue(<%=the_region%>)">
      
      
      
      <script language="javascript">
            javascript:window.close()
      </script>
      </body>
</html>
-----------------------
here's the code for the form in question on the home page:

<form name="register" action="reg_change.asp" method="post">
  <input type="hidden" name="w_region" size="24">
</form>
------------------------
Reg_Change.asp simply changes the page using ASP and Response.Redirect, so I don't think the problem is there.

Like I mentioned before, this all works perfect in Internet Explorer - but in FireFox it does not.  Is there anything I'm doing wrong?

An example can be seen at:  http://www.michiganweddingplanner.com (click on "Click Here to Change Your Region")

Thanks for your help!!!
0
Comment
Question by:steverguy
  • 3
7 Comments
 

Accepted Solution

by:
yasir710 earned 250 total points
ID: 17902067
Hi,

There is some difference in handling of JS by IE and FF. They both have different ways of refering to particular items and that is why your IE code is not working in FF.

I have re-written your kickback.asp page code as:

----------------------------------------------------------
<html>
<head>

<title>RegSend</title>
<script language="javascript">
     function changevalue(flag)
     {
          if (flag==1)
          {
               window.opener.document.register.w_region.value="1";
               window.opener.document.register.submit();
          }
          else if (flag==2)
          {
              // window.opener.document.register.w_region.value="2";
              //window.opener.document.register.submit();
               window.opener.parent.location='reg_change.asp?w_region=2';
                    
          }
          else if (flag==3)
          {
               window.opener.document.register.w_region.value="3";
               window.opener.document.register.submit();
          }
          else if (flag==4)
          {
               window.opener.document.register.w_region.value="4";
               window.opener.document.register.submit();
          }
          else if (flag==5)
          {
               window.opener.document.register.w_region.value="5";
               window.opener.document.register.submit();
          }
          else if (flag==6)
          {
               window.opener.document.register.w_region.value="6";
               window.opener.document.register.submit();
          }
          else if (flag==7)
          {
               window.opener.document.register.w_region.value="7";
               window.opener.document.register.submit();
          }
             
             
            }
            
            function closeMe()
            {
            window.close();
            }
</script>
</head>


     <body onload="closeMe();changevalue(2);">
     </body>
</html>

-----------------------------------------------------------

Note:
For testing purpose, I have used the value '2'.

See the condition where flag==2
   window.opener.parent.location='reg_change.asp?w_region=2';

You need to change the location of the parent page instead of submitting it and also specify the action URL in the location parameter.

Also, now you DON'T  need to add FORM in the home page. You can remove all the code within FORM tag as we have mentioned the action URL and parameter in the popup.

I hope this helps.

Regards
Yasir


0
 
LVL 2

Assisted Solution

by:jay_s5
jay_s5 earned 250 total points
ID: 17902119
Take a look at the errors your site is generating in Tools, Error Console in Firefox 2.0 (I think it was Tools, Javascript Console in Firefox 1.5.x) after you have clicked on the "change region" link.

When I tried the link in Firefox 2.0, it didn't work for me, either, and your site generated  a number of errors. Some are innocuous, and a couple weren't. With Firefox, if you have any Javascript errors, your Javascript functions may not work.

I would try fixing them and trying it again.

Although Firefox is much more strict than IE with what you can do with Javascript, redirects are possible.
0
 

Expert Comment

by:yasir710
ID: 17902199

I have got this unhandled expception in my FF 1.5.0.8

Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIObserverService.removeObserver]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: chrome://browser/content/browser.js :: BrowserShutdown :: line 873"  data: no]

As per the following URL, this might have caused by some other element on your page and not caused by the JS used.

http://www.howtocreate.co.uk/emails/CraigStrickland.html


Yasir
0
 

Expert Comment

by:yasir710
ID: 17902244

This exception might be caused by closing the FF window onLoad. See the following links:

http://forums.mozillazine.org/viewtopic.php?t=320478
http://weblogs.mozillazine.org/qa/archives/2005/08/need_to_get_som.html
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question