?
Solved

window.open doesn't work until I do a refresh

Posted on 2003-03-12
8
Medium Priority
?
325 Views
Last Modified: 2008-03-10
I have an ASP called CallReportInput.asp that opens one of two popup windows based on a selection from a dropdown box.  One of the pages, CallLogDayHistoryAll.asp, works all the time.  When trying to open the other, CallLogDayHistory.asp, I get the following error on CallReportInput.asp:



'self.opener.document' is null or not an object
Code: 0
URL: http://myserver/CallCenterReport/CallLogDayHistory.asp?inc=true



This only happens when first opening CallReportInput.asp.  If I refresh CallReportInput.asp, it works fine.
The dropdown on CallReportInput.asp looks like this:


   <font color="navy">View Calls for Today&nbsp;&nbsp;</font></td>
   <td valign=baseline><select name="ViewCalls" id="ViewCalls" onChange="OpenCallViewer()">
          <option value=0>Select a Viewer</option>
          <option value=0>--------------------------------------</option>
          <option value=1>View My Incomplete Calls</option>
          <option value=2>View All of My Calls</option>
<%If bolAdmin Then %>          
          <option value=3>View Incomplete Calls</option>
          <option value=4>View All Calls</option>
<%End If%>          
     </select>



Assuming bolAdmin is true, I select an option and it kicks off the following simple javascript function:



     function OpenCallViewer()
     {
     
      var newwin;
      if (document.frmReport.ViewCalls.value==1)
      {
      newwin = window.open('CallLogDayHistory.asp?inc=true',
          'DayHistory','resizable=yes,menubar=no,location=no,status=yes,scrollbars=yes');
      }
      if (document.frmReport.ViewCalls.value==2)
      {
      newwin = window.open('CallLogDayHistory.asp?inc=false',
          'DayHistory','resizable=yes,menubar=no,location=no,status=yes,scrollbars=yes');
      }
      if (document.frmReport.ViewCalls.value==3)
      {
      newwin = window.open('CallLogDayHistoryAll.asp?inc=true',
          'DayHistoryAll','resizable=yes,menubar=no,location=no,status=yes,scrollbars=yes');
      }
      if (document.frmReport.ViewCalls.value==4)
      {
      newwin = window.open('CallLogDayHistoryAll.asp?inc=false',
          'DayHistoryAll','resizable=yes,menubar=no,location=no,status=yes,scrollbars=yes');
      }
      newwin.focus()
     }


Now options 3 & 4 open up CallLogDayHistoryAll.asp fine.  But options 1 & 2 will only open CallLogDayHistory.asp if I first refresh CallReportInput.asp.  The Javascript on the two history pages is identical, as follows:




  <script>

//-------------------------------------------------------------------
// isNull(value)
//   Returns true if value is null
//-------------------------------------------------------------------

function isNull(val)
{
     return(val==null);
     
}

function LoadCallLog(url)
{
 openerwin.location.href=url;
}

var openerwin;
if (isNull(self.opener.document)==false)
{
     openerwin = self.opener.document;
}

 </script>





The only difference in the two history pages is some server-side vbscript which pulls different tables but shows similar results.

I tried creating a test page called CallLogDayHistoryTest.asp without any script - just a Hello World in html.  That page doesn't open at all, until I've done the refresh on CallReportInput.asp.

More info:  CallReportInput.asp is in an iFrame on a page within two framesets - not sure if this would prevent me from opening my test page or not.  I'm using IE 6.0.2800.1106 SP1.  Others in my office are using IE 5.5 and they get the javascript error when CallReportInput.asp loads, without even selecting an option.

What could possibly be wrong???  Why does one page open and a nearly identical pages doesn't, until I've refreshed the opener?

Much appreciated,
Marceau - MCSD



0
Comment
Question by:dmarceau
[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
8 Comments
 
LVL 6

Expert Comment

by:thomasdodds
ID: 8120744
you've assigned the windows to the same variable ... try with different variable names
0
 

Author Comment

by:dmarceau
ID: 8120794
Thanks for the reply.  Now, why would that matter?  Doesn't that variable go out of scope and get destroyed as soon as the function ends?
0
 
LVL 4

Expert Comment

by:anderson22
ID: 8121212
I would suggest updating your javascript function:

function OpenCallViewer()
{
     var newwin;
     var strURL = "";
     var strName = "";
     switch( document.frmReport.ViewCalls.options[document.frmReport.ViewCalls.selectedIndex].value )
     {
          case "1":
               strURL = "Cpopup.html?inc=true";
               strName = "DayHistory";
               break;
          case "2":
               strURL = "popup.html?inc=true";
               strName = "DayHistory";
               break;
          case "3":
               strURL = "popup.html?inc=true";
               strName = "DayHistoryAll";
               break;
          case "4":
               strURL = "popup.html?inc=true";
               strName = "DayHistoryAll";
               break;
     }
     newwin = window.open( strURL, strName, "resizable=yes,menubar=no,location=no,status=yes,scrollbars=yes" );
     newwin.focus()
}

you can see a demo of this here:
http://examples.pebuk.com/20547899/main.html
0
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 
LVL 6

Expert Comment

by:thomasdodds
ID: 8121355
I can't say for sure, but I saw something similar at work this past week and fixed it by dropping the VarName = window.open() syntax and used plain old window.open() and set the window name property to null and it worked... hope someone can shed light on why my fix worked - all I know is that was the work-around that proved good (at least for me)...
0
 

Author Comment

by:dmarceau
ID: 8121706
Thanks all for the help.  I think I've narrowed down the source of this problem but it doesn't solve anything.

Whenever I enter CallReportInput.asp into a browser by itself, it brings up a similar page called CallReportIndex.asp, which contains CallReportInput.asp in a frame.  When I hit refresh, it then brings up CallReportInput.asp by itself.  This was also happening in my iFrame I mentioned above, but I couldn't see what was happening inside the frame.  So that's what was causing all the wacky javascript errors.

The question now remains, why does CallReportIndex come up when I enter CallReportInput?  There are no vbScript Redirects or JavaScript location.href's to that page in CallReportInput.  Is this an IIS bug?  This happens on all other pc's including those with IE 5.5 & 6.0.
0
 

Author Comment

by:dmarceau
ID: 8122283
Solved it.  In the Global.asa there was a redirect in the Session start function (something a former employee created, that I didn't know about).  This is what was sending me to the incorrect page, which in turn was causing the JavaScript on the pages that that page opened to go haywire.

Thanks to everyone who took a lood at the code.  Much appreciated.

D. Marceau - MCSD
0
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 10652214
PAQed, with points refunded (75)

GhostMod
Community Support Moderator
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

752 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