document.getElementById('idname').onclick() is not working in IE

Hi, i have this code below.

<div id="container">
   <div>Welcome here</div>
  <div>Some content here</div>
<a href="somepage.html" id="p-overlay" rel="lyteframe" title="My Overlay page">&nbsp;</a>

<script type="text/javascript" language="JavaScript">
		function overlay(){

It works fine in Firefox, chrome and safari but not on IE. I got a run time error Object doesn’t support this property or method. I check the line number and the code is this document.getElementById(‘premiumoverlay’).onclick();

Any idea please on how to fix this? Anyhelp is much appreciated. Thank you

What exactly are you trying to do there, not real clear

Ok, once the page is loaded i want the lytebox to show up. Then, Lytebox will only show once href is clicked. So, to trigger href i have that document.getElementById('‘p-overlay).onclick()’;

The posted code says “p-overlay” while the error says “premiumoverlay”

It seems that you should search your script code for “premiumoverlay” and rename it to “p-overlay”

ahhh sorry, I actually edited my sample. In my actual script it is premiumoverlay.

May we please then load the problem page into our own web browser, with which to troubleshoot more effectively.

do you need a link?

That is commonly the easiest way.

While it is possible to attach zipped up files, it can take some time for access to them to be approved by higher-ups.

So yes, a link is a very good idea.

Here it is Sorry I have to cut because the system doesn’t allow me to post links.

It works fine in Firefox, Safari, Chrome but not on IE

Thank you.

This is the link:

<a href="" id="premiumoverlay" rel="lyteframe" title="Premium Pricing Program" rev="width: 700px; height: 350px; scrolling: no;"></a>

And this is the non-working script:


There is no onclick event that has been assigned to the link. Use the click event instead to simulate clicking on the link.

The working script:


It isn’t working anymore in FF, chrome and safari

In FF, it gives me this error
document.getElementById(“premiumoverlay”).click is not a function

then in IE it doesn’t appear as overlay page/lightbox style. It automatically redirects me to the overlay page link.

Intresting. Looks like IE will fire event handlers registered via traditional method before it will handlers registered via attachEvent()

This causes your function to run before the link gets an event handler assigned to it.

It’s kinda lame that your lytebox script automates the initialization. It should leave you in control of that. You can undo it’s doings though:

if (window.addEventListener) {
} else if (window.attachEvent) {
window.onload = function() {
		function overlay(){

huhuhu… it doesn’t work still. :frowning:

Okay, let’s go back to the onclick event.

We’ll have to wait for lytebox to complete doing its thing, so we’ll perform the onclick from a setTimeout after the page has loaded. Using 0 for the timeout doesn’t actually mean that the browser will run it immediately. It will be run whenever the browser is capable and ready, so 0 means “as soon as you’re capable”.

function overlay(){
    setTimeout(function () {
    }, 0);

specify the correct id.

He mentioned earlier that he changed them before posting them.

What’s happening is an onload conflict between lytebox and the onload script, resolved by asking the onload script to wait for a little bit longer.

Hey, thank you very much. It works fine now. Thank you thank you

I was going by what was in the page at that moment in time, not what was posted here. premium-overlay vs premiumoverlay

Good spotting there.
That solution script came afterwards when I decided to use <base href=“…”> to make sure that the test code would properly on the target page.

In my script i made sure that the id is correct.