最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Trying to use Greasemonkey to create a button that can run Javascript.- Stack Overflow

programmeradmin3浏览0评论

Website I'm on has a bunch of chat rooms that can be accessed via a dropdown menu. Problem is the Dropdown menu is generated via VBScript while the buttons themselves are Javascript. I have no problem using Internet Explorer, but a friend of mine really needs to use these rooms and cannot as she is on a mac. I'm trying to create a Greasemonkey script that will create these buttons elsewhere on the page so she can actually click on them, but I have no experience with Greasemonkey or Javascript at all.

When I right click a button in IE and choose Properties this is the code it gives me. I hope this is what you'd need to help, if not please let me know and I'll try to get what you need.

javascript:OpenWindow('/Portal/ChatTransfer.aspx?
chatroom=ATTNesting1&url=/
','','width=800px,height=600px,status=no,menubar=yes,
scrollbars=yes,titlebar=no,resizable=yes,toolbar=no,location=no');

Website I'm on has a bunch of chat rooms that can be accessed via a dropdown menu. Problem is the Dropdown menu is generated via VBScript while the buttons themselves are Javascript. I have no problem using Internet Explorer, but a friend of mine really needs to use these rooms and cannot as she is on a mac. I'm trying to create a Greasemonkey script that will create these buttons elsewhere on the page so she can actually click on them, but I have no experience with Greasemonkey or Javascript at all.

When I right click a button in IE and choose Properties this is the code it gives me. I hope this is what you'd need to help, if not please let me know and I'll try to get what you need.

javascript:OpenWindow('/Portal/ChatTransfer.aspx?
chatroom=ATTNesting1&url=https://chat02.arise./chat/
','','width=800px,height=600px,status=no,menubar=yes,
scrollbars=yes,titlebar=no,resizable=yes,toolbar=no,location=no');
Share Improve this question edited Jul 7, 2011 at 19:57 skaffman 404k96 gold badges824 silver badges775 bronze badges asked Jul 7, 2011 at 16:46 striderbetastriderbeta 11 silver badge1 bronze badge 2
  • Clarify. You use the menu, then a button appears, then you click that button for the chat? Your friend can see the menu, but the buttons don't appear? We need the code from the menu. Please either (A) link to the page, or, if that's not possible, (B) save the page's source to a file and upload that to pastebin./. – Brock Adams Commented Jul 7, 2011 at 21:19
  • Brock, the menu expands down from a smaller button when moused over and has several buttons for many different chat rooms. On IE the window pops out just fine, provided I run it in patibility mode for IE7. On Firefox the menu button shows up, but will not expand downward. On Chrome and Safari the menu button won't appear at all. Safari running in Develop mode IE7 will show the menu button, but the menu will not expand downward. Page link won't help as it's password protected. Pastebin tells me the source code file is too large. – striderbeta Commented Jul 7, 2011 at 22:21
Add a ment  | 

2 Answers 2

Reset to default 4

In short...

// create button
var btn = document.createElement( 'input' );
with( btn ) {
  setAttribute( 'onclick', 'alert( "you clicked me!" )' );
  setAttribute( 'value', 'click me!' );
  setAttribute( 'type', 'button' );
}

// append at end
document.getElementsByTagName( 'body' )[ 0 ].appendChild( btn );

This should add a button at the end of the page; of course you have to replace the alert() in the onclick-attribute with your desired OpenWindow()-function call. And I guess you have to address it with unsafeWindow.OpenWindow().

Another much-easier option is to make bookmarklets; bookmarks that execute javascript. Simply create a bookmark with each of the javascript: URLs and add void(0); to the end. Then you can click the bookmarks to do the actions.

发布评论

评论列表(0)

  1. 暂无评论