开发者

Frame overwrites the button?

dv = document.createElement('div'); // create dynamically div tag
    dv.setAttribute('id', "lyr1"); // give id to it
    dv.className = "top"; // set the style classname
    // set the inner styling of the div tag
    dv.style.position = "absolute";
    // set the html content inside the div tag
    dv.innerHTML = "<input id='serialize01' type='button' value='Serialize' onClick='objSerializeDOM.createXML(),objSerializeDOM.disableSerialize()'/>";

    // finally add the div id to your form
    document.body.insertBefore(dv, document.body.firstChild);

I am using this javascript code to put a button on every page of my domain.I achieve this using GreaseMonkey4IE plugin for IE.But the problem now is that it's not working for the web pages having frames.

file1.html

<html>
  <head>
   <title></title>
  </head>

  <frameset rows="50%,50%">
  <frame src="fr开发者_Go百科iends.html">

  </frameset>

</html>

main.html

<html>
<head>
<title>Joe and Jackie's friends</title>
</head>

<frameset cols="25%,75%">
  <frame src="file1.html">
</frameset>

</html>

friends.html

<html>
<head>
<title></title>
</head>
<body bgcolor="#ccffff">

Joe's friend<br>
<b>Bill</b>

</body>
</html>

When I deploy the above files using tomcat, the button is not showing up. To deploy :

1.I copied all three html files above and pasted'em inside a fodler named say folder1.

2.Copied folder1 inside webapps folder in tomcat directory.

3.Registered my .js file for domain(i.e,) localhost in GreaseMonkey4IE

4.Hit the URL from browser(IE8) i.e, http://localhost:8080/file1.html (button shows)

5.Hit the URL from browser i.e, http://localhost:8080/main.html (button does not show up.)

I guess whenever there are frames in the web page, it seems the button appended on the web-page get overwritten by the frame . :(

Any idea???

Is it by any way possible to get my button displayed ??

Thanks a lot.


If you can use php you may find it much easier to add in a global button by calling a php include script. I switched from using JavaScript to php and found it cleaned up allot of browsers problems because the buttons are added during page render instead of by the browsers on the users end.

example

<?php include('demo.php'); ?>

then just put your raw html in a file called "demo.php" then upload it in the same file and see if it works :)

good luck!


var frameSet = document.getElementsByTagName("frameset");
    if (frameSet[0] != null && frameSet[0] != undefined) {
        var frame = document.createElement('FRAME');
        frame.id = "frame1";
        frame.name = "frame1";
        frame.src = "";
        frameSet[0].rows = "40," + frameSet[0].rows;
        frameSet[0].insertBefore(frame, frameSet[0].firstChild);
        var frame = document.frames[0];
        var currentDocument = frame.document;
        currentDocument.write('<html> <body> <INPUT TYPE="submit" name="btn101" value="Serialize" onClick=""/>  <input id="checkbox101" type="checkbox">IncludeValues</input><br> </body> </html>');



I tried the above code and it worked for me.
This time I created a new frame and then put my button on it and finally added the frame as the first frame.
The code provided in the question will work only in case where the web pages don't have any frame.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜