IE href="javascript:customFunction()" not firing on first frame load
Asked Answered
F

3

7

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.

Footy answered 22/3, 2017 at 16:47 Comment(6)
Wow, didn't expect to see <frameset> that's been deprecated for a long time. None of this appears to be related to iframes.Funches
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.Weitzel
Can you provide a link to debug it?Midwinter
@KikoGarcia Sorry, it's an intranet thing. I even had to sanitize the information for security purposes.Footy
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?Mckown
@VivekAthalye if I open the debugger and look at the folder of assets there is the main .html page and that expands to reveal two "javascript:<URI>" files (?) and a folder of "dynamic scripts". If I click the navigation buttons then one of the "javascript:<URI>" becomes another .html file (same name as the main file). It appears the contents of the "javascript:<URI>" and the .html that replaces it are the same.Footy
V
4

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>
Virile answered 5/4, 2017 at 22:44 Comment(4)
No sandbox attributes exist. What strikes me as odd is that if I set a breakpoint inside of setDate() then it will fire when it works, but it won't fire when it doesn't work. As far as I can tell the browser just isn't firing any events. Additionally, we don't want to change the code as it's baked into a library that's used throughout our systems. If we were to try to change it we'd probably replace the entire thing with a javascript/html popup (uib-datepicker comes to mind) and rid ourselves of the frames altogether.Footy
@Footy How do you want to solve the problem, if you do not plan to change anything?Virile
We have two networks and are migrating users from one to the other. For some reason this code does not execute as described above on the new network, but works flawlessly on the old network. Identifying the cause should lead to a solution that doesn't involve changing the code...hopefully.Footy
@Footy I have some assumptions: 1) If your frame is not in the same domain, the browser should prevent such access for security reasons. 2) If you have events associated with checking the ready-state changes for <frame>, it have been discontinued by Internet Explorer 11. 3) Perhaps during the first boot, for some reason your javascript function not available. Try to load this function manually every time.Virile
H
3

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 commented 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.

Hackett answered 6/4, 2017 at 9:9 Comment(2)
Everything I've seen suggests that the code is the same before/after clicking the navigation buttons. Additionally, the code works in some environments on the first try without needing to use the navigation button. We've spent a fair bit of time looking through our various policies, firewalls, etc and we haven't found the culprit yet.Footy
Please help here (or.stackexchange.com/questions/5147/…) in re here (math.stackexchange.com/questions/1095760/…)Phlyctena
J
0

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

<a href='http://www.google.com' 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.

Jonejonell answered 7/4, 2017 at 8:41 Comment(1)
There is no explicit return statement for this function, it just sets values of other properties and calls other methods. However, this function is never called when the problem exists. When it does work I can set a breakpoint and it'll break on the first line of the method, but when it doesn't work it won't break at all.Footy

© 2022 - 2024 — McMap. All rights reserved.