943,884 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Aug 18th, 2009
0

Top page Banner script

Expand Post »
Hello, I need a script that will be added after </body> and will be displayed at the top of the page.
I know is posible, I have one :

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. var object = document.createElement('div');
  3. object.innerHTML = 'The banner script is HERE';
  4. var body = document.getElementsByTagName('body')[0];
  5. body.insertBefore(object, body.firstChild);
  6. </script>

The problem with this cod is that is shows in forum phpbb3 in the login page and after is loged in twice in the header.

Can someone help me here ?

Kind regards.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
b0tz is offline Offline
15 posts
since Jul 2008
Aug 18th, 2009
0

Re: Top page Banner script

I'm not a big PHPBB man myself and i had trouble understanding exactly what is happening to your code but one regular problem with forums is them interpreting code as text expecially when it comes to javascript.

a workaround can be to create page hosted elsewhere on the server and link to that to execute the code.

Please could you be more clear about what is happening and perhaps provide a link?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MattTheHat is offline Offline
10 posts
since May 2009
Aug 18th, 2009
0

Re: Top page Banner script

Hi everyone,

the first-child access will only work if you have no other nodes' next to the target element. So the safest way to get the 1st-element would be:

javascript Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  2. <?xml-stylesheet type="text/css" href="#css21" media="screen"?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  4. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  5. <html id="xhtml10S" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6. <head>
  7. <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <meta http-equiv="Content-Style-Type" content="text/css" />
  10. <meta http-equiv="Content-Script-Type" content="text/javascript" />
  11. <title>Free Live Help!</title>
  12. <style type="text/css" id="css21">
  13. /* <![CDATA[ */
  14. @namespace url( http://www.w3.org/1999/xhtml );
  15.  
  16. body {
  17. background-color : #FFF;
  18. color : #405060; }
  19.  
  20.  
  21. /* ]]> */
  22. </style>
  23. <script type="text/javascript">
  24. // <![CDATA[
  25. window.onload = function() {
  26. if ( document.createElement ) {
  27. var body = document.getElementsByTagName("body")[ 0 ];
  28. var fChild = body.getElementsByTagName("*")[ 0 ];
  29. var obj = document.createElement("div");
  30. obj.appendChild( document.createTextNode("The banner script is here."));
  31. body.insertBefore( obj, fChild );
  32. return;
  33. } alert("unsupported features, please upgrade your browser");
  34. return false;
  35. }
  36. // ]]>
  37. </script>
  38. </head>
  39. <body>
  40. <noscript id="noscript">
  41. <p>This website requires <b>JavaScript</b> support.</p>
  42. </noscript>
  43. <div id="div">First Div</div>
  44. </body>
  45. </html>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Aug 18th, 2009
0

Re: Top page Banner script

@MattTheHat

Here is a link where the ads are displayed 2 times.

http://www.ionut.totalh.com/forum/ucp.php?mode=login

@essential

I just want to understand corecly, are you saying that the JS is looking for the <body> tag and if is found more the 1 time, the ad code is shows the exact number of times, found in the php/html page ?

If so, the JS provided by you, is going to stop at the first <body> tag and display only one time ?

By the way, I can only put the JS cod AFTER </body> BEFORE </html>/ ?>

Thank for your help.

LE: In the JS cod provided, can I add my html script ?
Last edited by b0tz; Aug 18th, 2009 at 8:18 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
b0tz is offline Offline
15 posts
since Jul 2008
Aug 18th, 2009
0

Re: Top page Banner script

Hi b0tz,

here's your requested script that does the same application and based in your posted code. This script is enhanced by a statement that prevents duplication of dynamic div.

code is as follows:
javascript Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <meta http-equiv="Content-Script-Type" content="text/javascript">
  7. <title>www.daniweb.com</title>
  8. </head>
  9. <body id="body">
  10. <div id="div0">Element 1</div>
  11. <div id="div1">Element 2</div>
  12. <!-- more stuff... -->
  13. </body>
  14. <script type="text/javascript">
  15. <!--
  16. ( function() {
  17. var isBody = document.getElementsByTagName("body")[ 0 ];
  18. if ( "createElement" in document ) {
  19. var isObject;
  20. if ( isObject = document.getElementById("newDiv")) { // this will prevent duplication of dynamic div.
  21. return false;
  22. } isObject = document.createElement( "div" );
  23. isObject.id = "newDiv";
  24. isObject.appendChild( document.createTextNode("The banner script is HERE."));
  25. isBody.insertBefore( isObject, isBody.firstChild );
  26. }
  27. } )( /* JavaScript 1.5 */ );
  28. // -->
  29. </script>
  30. </html>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Aug 18th, 2009
0

Re: Top page Banner script

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. isObject.appendChild( document.createTextNode("The banner script is HERE."));
I don't think that this will help me add html code.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <meta http-equiv="Content-Script-Type" content="text/javascript">
  7. <title>www.daniweb.com</title>
  8. </head>
  9. <body id="body">
  10. <div id="div0">Element 1</div>
  11. <div id="div1">Element 2</div>
  12. <!-- more stuff... -->
  13. </body>
  14. <script type="text/javascript">
  15. <!--
  16. ( function() {
  17. var isBody = document.getElementsByTagName("body")[ 0 ];
  18. if ( "createElement" in document ) {
  19. var isObject;
  20. if ( isObject = document.getElementById("newDiv")) { // this will prevent duplication of dynamic div.
  21. return false;
  22. } isObject = document.createElement( "div" );
  23. isObject.id = "newDiv";
  24. isObject.appendChild( document.createTextNode("<center><iframe allowtransparency=\"true\" align=\"center\" src=\"http://www.site.org/links.php\" scrolling=\"no\" marginheight=\"0\" frameborder=\"0\" width=\"900px\"height=\"18px\"></iframe><iframe align=\"center\" src=\"http://www.site.org/frame.php\" allowtransparency=\"true\" scrolling=\"no\" marginheight=\"1\" frameborder=\"0\" width=\"900px\" height=\"92px\"></iframe></center>"));
  25. isBody.insertBefore( isObject, isBody.firstChild );
  26. }
  27. } )( /* JavaScript 1.5 */ );
  28. // -->
  29. </script>
  30. </html>
The output is showing only the text that I put there.

Thanks
Last edited by b0tz; Aug 18th, 2009 at 11:42 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
b0tz is offline Offline
15 posts
since Jul 2008
Aug 18th, 2009
0

Re: Top page Banner script

Sorry i thought that it was just a simple text insertion. Here's modified version and configured according to your needs:

javascript Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <meta http-equiv="Content-Script-Type" content="text/javascript">
  7. <title>www.daniweb.com</title>
  8. </head>
  9. <body id="body">
  10. <!-- DO NOT REMOVE THIS COMMENT, UNLESS YOU HAVE OTHER NODES IN THE BODY DOCUMENT! -->
  11. </body>
  12. <script type="text/javascript">
  13. <!--
  14. ( function() {
  15. var content;
  16. var isBody = document.getElementsByTagName("body")[ 0 ];
  17. if ( "createElement" in document ) {
  18. var isObject;
  19. if ( isObject = document.getElementById("newDiv")) { // this will prevent duplication of dynamic div.
  20. return false;
  21. } isObject = document.createElement( "div" );
  22. isObject.id = "newDiv";
  23. var cent = document.createElement("center");
  24. var iAttr = {
  25. allowtransparensy : true,
  26. align : "center",
  27. marginheight : 0,
  28. width : 900,
  29. scrolling : "no",
  30. frameborder : 0 };
  31. var iframe1 = document.createElement('iframe');
  32. var iframe2 = document.createElement('iframe');
  33. for ( var attr in iAttr ) {
  34. var i1attr = document.createAttribute( attr );
  35. var i2attr = document.createAttribute( attr );
  36. i1attr.nodeValue = iAttr[ attr ];
  37. i2attr.nodeValue = iAttr[ attr ];
  38. iframe1.setAttributeNode( i1attr );
  39. iframe2.setAttributeNode( i2attr );
  40. }
  41. iframe1.height = 18;
  42. iframe2.height = 96;
  43. // CACHING OVER ITS LOCATION.
  44. var i1path = new Image();
  45. var i2path = new Image();
  46. i1path.src = "http://www.site.org/link.php";
  47. i2path.src = "http://www.site.org/frame.php";
  48. cent.appendChild( iframe2 );
  49. cent.insertBefore( iframe1, iframe2 );
  50. isObject.appendChild( cent );
  51. isBody.insertBefore( isObject, isBody.firstChild );
  52. iframe1.location = i1path.src;
  53. iframe2.location = i2path.src;
  54. }
  55. } )( /* JavaScript 1.5 */ );
  56. // -->
  57. </script>
  58. </html>
Last edited by essential; Aug 18th, 2009 at 1:22 pm.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Aug 18th, 2009
0

Re: Top page Banner script

wow, you even put my iframe codes. Thank you. I will test them right now and see if are working.

Thank you very much.

I will reply here when all is working. It should take around 20 minutes to update to server.

Thanks again.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
b0tz is offline Offline
15 posts
since Jul 2008
Aug 18th, 2009
0

Re: Top page Banner script

I just inserted the cod in a test page and I don't think the iframe is working.

The 2 iframes are :

http://www.site.org/links.php
http://www.site.org/frame.php

In the attached file you will see the exact URL, I will not spam here.

Can you take a look ?

Thank you.
Attached Files
File Type: txt index.txt (11.9 KB, 29 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
b0tz is offline Offline
15 posts
since Jul 2008
Aug 18th, 2009
0

Re: Top page Banner script

Hi b0tz,

this script works fine with me and load the target location on the iframes' on a localhost, hope it'll do the same thing inside your browser and as well as with your server:

javascript Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <meta http-equiv="Content-Script-Type" content="text/javascript">
  7. <title>www.daniweb.com</title>
  8. </head>
  9. <body id="body">
  10. <!-- DO NOT REMOVE THIS COMMENT, UNLESS YOU HAVE OTHER NODES IN THE BODY DOCUMENT! -->
  11. </body>
  12. <script type="text/javascript">
  13. <!--
  14. ( function() {
  15. var content;
  16. var isBody = document.getElementsByTagName("body")[ 0 ];
  17. if ( "createElement" in document ) {
  18. var isObject;
  19. if ( isObject = document.getElementById("newDiv")) { // this will prevent duplication of dynamic div.
  20. return false;
  21. } isObject = document.createElement( "div" );
  22. isObject.id = "newDiv";
  23. var cent = document.createElement("center");
  24. var iAttr = {
  25. allowtransparensy : true,
  26. align : "center",
  27. marginheight : 0,
  28. width : 900,
  29. scrolling : "no",
  30. frameborder : 0 };
  31. var iframe1 = document.createElement('iframe');
  32. var iframe2 = document.createElement('iframe');
  33. for ( var attr in iAttr ) {
  34. var i1attr = document.createAttribute( attr );
  35. var i2attr = document.createAttribute( attr );
  36. i1attr.nodeValue = iAttr[ attr ];
  37. i2attr.nodeValue = iAttr[ attr ];
  38. iframe1.setAttributeNode( i1attr );
  39. iframe2.setAttributeNode( i2attr );
  40. }
  41. iframe1.height = 18;
  42. iframe2.height = 96;
  43. cent.appendChild( iframe2 );
  44. cent.insertBefore( iframe1, iframe2 );
  45. isObject.appendChild( cent );
  46. isBody.insertBefore( isObject, isBody.firstChild );
  47. ( iframe1.src = iframe2.src = ( function() { // Change your desired URL from here >>>
  48. var url = "http://www.fnhost.org/test/index.html";
  49. var path = new Image()
  50. path = ( path.src = url );
  51. return path;
  52. } )( ));
  53. }
  54. } )( /* JavaScript 1.5 */ );
  55. // -->
  56. </script>
  57. </html>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: copy image url to an open form field???
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Associative Array in Javascript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC