Solved

Javascript in FireFox

Posted on 2006-11-03
7
775 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now