获取第一个h1标题,并在新选项卡中打开<server_name>h1.html
Get first h1 heading and open <server_name>h1.html in new tab
我得到了两个带有以下代码的选项卡-一个表示[object Window],另一个显示我想要的页面。
-
怎样才能摆脱第一个无用的标签?
-
有没有办法让书签打开http:///getting_started_txt_(random_alphanumeric_code_here).html ?
…我需要打开一个页面,该页面只匹配离线文件名的h1部分,文件名开始,然后是一些胡言乱语。
我这边的脱机文件类似于"getting_started_txt_23468j5jg86458jm34858.html"。因此,bookmarklet必须查找文件名以"带下划线的h1"开头的文件以及其后的任何内容。这可能吗?
window.open('http://en.wikipedia.org/wiki/' + document.getElementsByTagName('h1')[0].innerHTML.replace(/<[^>]+>/g, '').replace(/ /g, '_') + '_txt_');
所以如果我打开了一个页面,第一个标题是h1作为"getting started",书签小工具应该打开一个URL为http://(server_name)/getting_started_txt_(random_alphanumeric_code_here).html
的新选项卡。
请注意,服务器上只有一个文件与geting_started_txt部分匹配,文件名的其余部分可以是任何内容。
这样的操作在大多数情况下应该可以工作。
window.open('''''server_name''en''' + encodeURIComponent(document.getElementsByTagName('h1')[0].innerHTML.replace(/<[^>]*>/g, '').replace(/'s/g, '_')) + '.html', 'win')
bookmarklet应该是这样的:
javascript:window.open('http://en.wikipedia.org/wiki/' + document.getElementsByTagName('h1')[0].innerHTML.replace(/<[^>]+>/g, '').replace(/ /g, '_'));
或者这个(url编码的版本):
javascript:window.open%28%27http%3A//en.wikipedia.org/wiki/%27%20%252B%20document.getElementsByTagName%28%27h1%27%29%5B0%5D.innerHTML.replace%28/%3C%5B%5E%3E%5D%252B%3E/g%2C%20%27%27%29.replace%28/%20/g%2C%20%27_%27%29%29%3B
这些是JavaScript代码的简化版本:
// Find the first H1 node
var h1 = document.getElementsByTagName('h1')[0];
// Extract the content of the node
var title = h1.innerHTML;
// Delete HTML tags in the content of the title
title = title.replace(/<[^>]+>/g, '');
// Replace spaces with underscore symbols
title = title.replace(/%s/g, '_');
// Open a new window (or tab) with the corresponding Wikipedia article
window.open('http://en.wikipedia.org/wiki/' + title);
- 可以't让我的if语句处理js中的html表单输入
- 如何设置html元素填充的动画
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 如何编写HTML输入的JS内联
- Dojo不解析自定义小部件的模板html中的小部件声明性
- 使用javascript将动态表从一个html页面打印到另一个html页
- 通过javascript重定向html传递php变量
- 如何使Javascript动态html表及其上的事件
- 在chrome.tabs.onCreated之后加载HTML页面
- 如何在vs2002中调试html页面
- 如何使用javascript或html下载PDF格式的填写表单
- 视频HTML没有'无法在Internet Explorer 11上工作
- HTML表单提交时未执行外部函数
- 如何将输入(type=text)从html表单传递到javascript函数
- 如何通过单击html按钮获得h1的文本值
- 从 Java 服务器加载 JSON ajax 后无法获取 h1 标记的内部 HTML
- 多个$http.get请求,每个JSON文件在HTML中以h1分隔
- 基于h1动态更新html元素值
- 获取第一个h1标题,并在新选项卡中打开
h1.html