home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Triggering myself

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2789
Discussions: 200,966, Posts: 2,379,647, Members: 246,332
Old February 2nd, 2007, 10:17 AM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Feb 2007
Posts: 3
Triggering myself

Hi everybody,
I was playing around this since a while, without any succes, then I left it as it was. Now I have another place, where it would be quite useful for me.
Let's say, there is an existing div tga.
I give some content to the innerHTML of the div. The new content has soma javascript code, but as we know, the interpreter will not intrpret the new content. How could I get triggered the div tag from "itself"?
I would like to get the alert executed... The text appears, but the alert does not... Any idea. Please help me.
Gregor
<div id="myid">Old content</div>
<script>
oElement = document.getElementById('myid');
oElement.innerHTML='New content<script>new Function("alert(\'I would like to see this\');");<\/script>';
</script>
Albino is offline   Reply With Quote
Old February 2nd, 2007, 02:58 PM     #2 (permalink)
Banned
 
Iturea's Avatar
 
Join Date: Jan 2004
Location: Earth
Posts: 420
Wink
Works in IE 7

The key is deferring execution of a script block. You are basically tricking IE 7 to put the block in memory for execution. Firefox is a little smarter, so this won't work in Firefox...

You can test this logic by commenting out this line:
oElement1.innerHTML = oElement2.innerHTML
it won't trigger unless you have the above line...

It also won't trigger unless you defer the new content script block. This makes IE put the block of code in memory! I don't know if this is a security exploit or not... Firefox just ignores it (Go Firefox!!!)

Once you transfer the new div to the old div the alert gets triggered.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>     
    <title>Defer Execution</title>
    <script type="text/javascript" language="JavaScript" xml:space="preserve">
      var triggered = false;
    </script>
  </head>
  <body>  
    <div id="oldcontent">
      Old content
    </div>
    <div id="newcontent" style="display:none;">
      New Content
      <script type="text/javascript" language="JavaScript" xml:space="preserve" defer="defer">
        if (triggered)
        {
          triggered = false;
          //Lets see what we have in oldcontent!!!
          alert(document.getElementById('oldcontent').innerHTML);
        }
        triggered = true;
      </script>
    </div>
    <script type="text/javascript" language="JavaScript" xml:space="preserve">
      //<![CDATA[
      oElement1 = document.getElementById('oldcontent'); 
      oElement2 = document.getElementById('newcontent');
      oElement1.innerHTML = oElement2.innerHTML;
      //]]>
    </script>
  </body>
</html>
Every browser uses the defer attribute differently, so there really isn't one code does all trick to make this work... You will need to make conditions for other browsers..

Good luck...

Last edited by Iturea : February 2nd, 2007 at 04:13 PM.
Iturea is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Triggering port triggering? Andgasm Networking and Internet 4 January 4th, 2006 03:04 AM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3015)
Forty-six years ago today (9)
The disrespect of Obama by Russian .. (46)
Laptop with wireless problem. (12)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
Internet Lost (5)
windows 7 problem (7)
windows vista security holes (15)
Point and Shoot Camera Suggestions. (6)
Is the PSU I received dead? (13)
radeon x850xt platinum & shader.. (6)
HIS HD5770 graphic card question (15)
Recent Discussions
Open With ..... Win7 (3)
windows vista security holes (15)
Help getting around port 80 for camer.. (4)
Laptop with wireless problem. (12)
Internet Lost (5)
Skillsoft Network+ Study Software Que.. (9)
virus blocking exe. files (1)
Point and Shoot Camera Suggestions. (6)
CPU fan stops spinning randomly (11)
Nvidia GTX 260 problem (1)
Modern Warfare 2: Who Bought It? (65)
Is the PSU I received dead? (13)
Print spooler problem (16)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
webcam (0)
upgrade for hp a6101 (0)
tv not turn on-makes clicking sound (2)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
Ideal cheap graph card for PC-Gaming? (18)


All times are GMT -4. The time now is 03:26 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28