Solved

Javascript in FireFox

Posted on 2006-11-03
7
791 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Part One of the two-part Q&A series with MalwareTech.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

636 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