473,320 Members | 2,189 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Execute code in onload event. e.g. eval(element.getAttribute('onload'));

I need to execute code in an onload event.

Expand|Select|Wrap|Line Numbers
  1. e.g. eval(element.getAttribute('onload'));
This works in Firefox but not in IE (surprise!). IE's getAttribute for the onload event seems to return an anonymous function or something. Any ideas or hacks anyone?

Thanks!
Mar 1 '07 #1
4 5415
acoder
16,027 Expert Mod 8TB
Welcome to The Scripts.

See this link and see if it helps.
Mar 1 '07 #2
Welcome to The Scripts.

See this link and see if it helps.
Thanks for the welcome! This site has been helpful in the past too.

Yeah thanks for the suggestion, I looked at that site already, it helped a bit, but I still haven't found a solution (for IE) that allows me to execute the contents of what is in the onload event for an element, in this case the body tag. I've played around with document.body.onload(), window.onload(), nothing seems to work.

I don't have access to the body tag of the page I'm working on and I need to manually run the js in the body onload event.

I tried using outerHTML to grab the contents of the body tag, but the onload event code seems to be stripped off from there.

The latest thing I've been playing with is making an XMLHttpRequest to itself and putting the contents in a string variable (basically it grabs the source of the current page). Then, using regular expressions, find the onload code, and eval() it. Not a very great solution, but it might work.

I'm free to any suggestions.

Thanks!
Mar 1 '07 #3
Thanks for the welcome! This site has been helpful in the past too.

Yeah thanks for the suggestion, I looked at that site already, it helped a bit, but I still haven't found a solution (for IE) that allows me to execute the contents of what is in the onload event for an element, in this case the body tag. I've played around with document.body.onload(), window.onload(), nothing seems to work.

I don't have access to the body tag of the page I'm working on and I need to manually run the js in the body onload event.

I tried using outerHTML to grab the contents of the body tag, but the onload event code seems to be stripped off from there.

The latest thing I've been playing with is making an XMLHttpRequest to itself and putting the contents in a string variable (basically it grabs the source of the current page). Then, using regular expressions, find the onload code, and eval() it. Not a very great solution, but it might work.

I'm free to any suggestions.

Thanks!

this seems to work:
Expand|Select|Wrap|Line Numbers
  1. var attr = element.getAttribute('onload');
  2. typeof attr == 'function' ? attr() : eval(attr);
Mar 2 '07 #4
acoder
16,027 Expert Mod 8TB
this seems to work:
Expand|Select|Wrap|Line Numbers
  1. var attr = element.getAttribute('onload');
  2. typeof attr == 'function' ? attr() : eval(attr);
Yes, in the link, this is mentioned in one of the comments. Glad you got it working in the end.
Mar 3 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bender | last post by:
Hi, I am wanting to capture an onmousedown event without firing the body tags onload event. Also, if anyone could explain why this happens that would be excellent. I can't see how an...
4
by: Pai | last post by:
hello there, I am trying to rersize the window it works find in IE but doea not work with mozilla window.attachEvent(onload,MWSOnLoad); window.onload = function (MWSOnLoad) { alert('hello');...
6
by: Brian | last post by:
Hi everyone, I'm writing a function (in javascript) that needs to do one thing if the page has not loaded, and another (different) thing if the page has already loaded. I'm looking for a way...
4
by: UJ | last post by:
I have some javascript code that I need to run based on a value I know at the server when I load a page. How can I do an onload event call with a condition value from the server. (The reason is...
5
by: Andy Fish | last post by:
Hi, I have an asp.net web application which uses a pop-up form that works a bit like a dialog box. when the user clicks "OK" it does a postback (basically a form post if you don't know .net) to...
1
by: thomasjvi | last post by:
what is the difference between calling javascript method in the onLoad event along with the form and invoking the method directly from the JSP. I want to execute some code part when the page load...
6
by: pronerd | last post by:
Hi, I am trying to dynamically set an event handler across frames. I have no problems setting properties across frames doing something like parent.ToolMenuFrame.location.href =...
6
by: Daz | last post by:
Hello everyone, I would like to open a child window from the parent, and add an onload event listener to the child window which will tell the parent when the document has loaded. As far as I...
1
by: webgour | last post by:
Hello, I would like to create an onload event within my object. The following works fine : function TEST() { this.image= new Image(); } TEST.prototype.Initialize = function()
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.