admin管理员组

文章数量:1400157

I have a custom date picker popup that isn't working in IE sometimes. It works in Chrome and Edge fine.

The code looks something like this:

<frameset>
    <frame>Buttons for next/prev month/year</frame>
    <frame>This is the actual calendar that gets redrawn when the above buttons are used
        <a href="javascript:parent.opener.setDate(1);">1</a> //there's a different anchor tag for each day of the month
    </frame>
<frameset>

So here's where it gets kind of weird. We have two networks, call them old and new. Old has probably a lot of undocumented global policy changes and new is probably close to the gov standard. This works on any browser on the old network, but not IE (11) on the new network. It works in Edge though. Additionally, if the top frame buttons are used to pick the next/prev month, or just the "Today" button, then all of the bottom frame anchor links work normally. There are no console errors/warnings, nothing in the network monitor showing a request returned an error code, the clicks just don't register. I put a breakpoint inside customFunction() and it won't break when the links don't work, but it will break if the link will work.

The only other thing that seems odd to me is that the code for the whole popup looks something like:

str = "<frameset><frame name='topFrame' " + 
    "src='javascript:parent.opener.drawTop'></frame><frame name='bottomFrame' "+
    "src='javascript:parent.opener.drawBottom'><frame</frameset>"

document.write(str);

I did look to check and the code that redraws the bottom frame when the prev/next/etc buttons are used is the same function that gets called during the first load.

However, what seems odd about this is that on the first load the DOM inspector shows everything (top frame, bottom frame including all the individual numbers for each day of the month, etc), but the Debugger (F12 tools) doesn't show the code loaded with the document.write(str); line. To be able to see that code and set break points I have to use the prev/next buttons and then an additional .html file shows up in Debugger which has the constructed HTML that matches the DOM.

I have a custom date picker popup that isn't working in IE sometimes. It works in Chrome and Edge fine.

The code looks something like this:

<frameset>
    <frame>Buttons for next/prev month/year</frame>
    <frame>This is the actual calendar that gets redrawn when the above buttons are used
        <a href="javascript:parent.opener.setDate(1);">1</a> //there's a different anchor tag for each day of the month
    </frame>
<frameset>

So here's where it gets kind of weird. We have two networks, call them old and new. Old has probably a lot of undocumented global policy changes and new is probably close to the gov standard. This works on any browser on the old network, but not IE (11) on the new network. It works in Edge though. Additionally, if the top frame buttons are used to pick the next/prev month, or just the "Today" button, then all of the bottom frame anchor links work normally. There are no console errors/warnings, nothing in the network monitor showing a request returned an error code, the clicks just don't register. I put a breakpoint inside customFunction() and it won't break when the links don't work, but it will break if the link will work.

The only other thing that seems odd to me is that the code for the whole popup looks something like:

str = "<frameset><frame name='topFrame' " + 
    "src='javascript:parent.opener.drawTop'></frame><frame name='bottomFrame' "+
    "src='javascript:parent.opener.drawBottom'><frame</frameset>"

document.write(str);

I did look to check and the code that redraws the bottom frame when the prev/next/etc buttons are used is the same function that gets called during the first load.

However, what seems odd about this is that on the first load the DOM inspector shows everything (top frame, bottom frame including all the individual numbers for each day of the month, etc), but the Debugger (F12 tools) doesn't show the code loaded with the document.write(str); line. To be able to see that code and set break points I have to use the prev/next buttons and then an additional .html file shows up in Debugger which has the constructed HTML that matches the DOM.

Share Improve this question edited Mar 22, 2017 at 16:50 zzzzBov 179k56 gold badges327 silver badges371 bronze badges asked Mar 22, 2017 at 16:47 tenmilestenmiles 2,7513 gold badges19 silver badges21 bronze badges 6
  • 1 Wow, didn't expect to see <frameset> that's been deprecated for a long time. None of this appears to be related to iframes. – zzzzBov Commented Mar 22, 2017 at 16:50
  • 4 A closing tag is wrong at the end of the str definition: <frame</frameset>. It should be </frame></frameset>. I don't know if that is a typo in your post or if it is also present in your actual code. – Martin Parenteau Commented Mar 31, 2017 at 12:21
  • Can you provide a link to debug it? – Kaique Garcia Commented Apr 4, 2017 at 0:01
  • @KikoGarcia Sorry, it's an intranet thing. I even had to sanitize the information for security purposes. – tenmiles Commented Apr 4, 2017 at 17:45
  • What do you mean by an additional .html file shows up in Debugger? Is it loading that piece of html from some URL when you click on prev/next buttons? – Vivek Athalye Commented Apr 7, 2017 at 9:18
 |  Show 1 more ment

3 Answers 3

Reset to default 4 +225

try this:

1)

<a href="javascript:parent.opener.setDate(1); void(0);">1</a>

2)

<a href="javascript:function(){parent.opener.setDate(1); return false;}">1</a>

3)

<a href="#" onclick="javascript:parent.opener.setDate(1); return false;">1</a>

4) check your code. Maybe your frame has attribute 'sandbox'. This attribute can block javascript. Example:

 <iframe src="URL" sandbox>

Aside from the great suggestions by Nutscracker, I've also had my share of vague problems with document.write and event handlers not attaching in IE. The problem mented on by ConnorsFan could be the cause here, but you could also try:

document.body.innerHTML = '<frameset><frame name="topFrame" ' + 
'src="javascript:parent.opener.drawTop"></frame><frame name="bottomFrame" '+
'src="javascript:parent.opener.drawBottom"><frame></frameset>'

You might also want to check this code is actually being called, maybe the real working popup is loaded from somewhere else by the prev/next buttons and this is just some leftover stuff.

If your onclick function returns false the default browser behaviour is cancelled. As such:

<a href='http://www.google.' onclick='return check()'>check</a>

<script type='text/javascript'>

function check()
{
    return false;
}

This means that you can set your JavaScript function as an onclick event, and just have the anchor tag linking back to the page you are on - as it won't redirect you when you click it but needs a href attribute.

本文标签: internet explorerIE hrefquotjavascriptcustomFunction()quot not firing on first frame loadStack Overflow