Browser: modify DOM (executing javascript)
来源:互联网 发布:知羽电子相册模板 编辑:程序博客网 时间:2024/06/03 11:44
Web browser执行javascript
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Browser example snippet: modify DOM (executing javascript)
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*
* @since 3.1
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class JavascriptExec {
public static void main(String[] args) {
final String = "< ><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></ >";
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Browser browser = new Browser(shell, SWT.BORDER);
Composite comp = new Composite(shell, SWT.NONE);
comp.setLayout(new FillLayout(SWT.VERTICAL));
final Text text = new Text(comp, SWT.MULTI);
text.setText("var newNode = document.createElement('P'); /r/n"
+ "var text = document.createTextNode('At least when I am around');/r/n"
+ "newNode.appendChild(text);/r/n"
+ "document.getElementById('myid').appendChild(newNode);/r/n" + "/r/n"
+ "document.bgColor='yellow';");
final Button button = new Button(comp, SWT.PUSH);
button.setText("Execute Script");
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
boolean result = browser.execute(text.getText());
if (!result) {
/* Script may fail or may not be supported on certain platforms. */
System.out.println("Script was not executed.");
}
}
});
browser.setText();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
/*
* Browser example snippet: modify DOM (executing javascript)
*
* For a list of all SWT example snippets see
* http://www.eclipse.org/swt/snippets/
*
* @since 3.1
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class JavascriptExec {
public static void main(String[] args) {
final String = "< ><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></ >";
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Browser browser = new Browser(shell, SWT.BORDER);
Composite comp = new Composite(shell, SWT.NONE);
comp.setLayout(new FillLayout(SWT.VERTICAL));
final Text text = new Text(comp, SWT.MULTI);
text.setText("var newNode = document.createElement('P'); /r/n"
+ "var text = document.createTextNode('At least when I am around');/r/n"
+ "newNode.appendChild(text);/r/n"
+ "document.getElementById('myid').appendChild(newNode);/r/n" + "/r/n"
+ "document.bgColor='yellow';");
final Button button = new Button(comp, SWT.PUSH);
button.setText("Execute Script");
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
boolean result = browser.execute(text.getText());
if (!result) {
/* Script may fail or may not be supported on certain platforms. */
System.out.println("Script was not executed.");
}
}
});
browser.setText();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
- Browser: modify DOM (executing javascript)
- Modify CSS with JavaScript
- javascript prototype,executing,context,closure
- javascript Browser对象篇
- JavaScript中Browser 对象
- JavaScript in the browser
- js对象 && Browser对象 && DOM对象
- [DOM]javascript DOM操作
- NPN_Evaluate execute javascript in browser
- how javascript loaded in browser
- Javascript detecting a mobile browser
- javaScript对象与browser对象
- Javascript DOM
- javascript--dom
- JavaScript DOM
- Dom ,JavaScript
- Javascript DOM
- javascript Dom
- RFCOMM Chat 简单的BT聊天实例
- Java 集合类简述
- 在作缓存时使用SqlCacheDependency
- Modify HTML title tag 可以从这个例子得到启发如何修改DOM的元素
- 特效网站
- Browser: modify DOM (executing javascript)
- 设计模式随笔(二):工厂方法(Factory Method)
- jar参数运行应用时classpath的设置方法
- Prototype 学习——Array对象
- Query DOM node value
- [Flex]Flex SDK 4(Gumbo)更方便的自定义样式、自定义SparkSkin(三)
- 自己封装的ajax
- NEW详解
- vc ado 数据库